X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Ftests.cpp;h=8e24bb52facc436a0a75451a57726737a574bb22;hp=5b34bf69d9d37fc732c4f45c5ea1c55a41394be1;hb=6a832fe1771f8c7bca0faa0d383fbbab062a1c56;hpb=ceae2a27dfc58310c5bab7e3aa3fedf0fa9a1f49 diff --git a/source/tests.cpp b/source/tests.cpp index 5b34bf69..8e24bb52 100644 --- a/source/tests.cpp +++ b/source/tests.cpp @@ -1,28 +1,72 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #include "tests.h" namespace Msp { namespace GL { -void scissor(int left, int bottom, unsigned width, unsigned height) +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() { - glScissor(left, bottom, width, height); + static DepthTest test(LEQUAL); + return test; } -void alpha_func(Predicate func, float ref) +void DepthTest::unbind() +{ + if(set_current(0)) + { + glDisable(GL_DEPTH_TEST); + // Allow glClear(GL_DEPTH_BUFFER_BIT) to work + glDepthMask(true); + } +} + + +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 { - glAlphaFunc(func, ref); + if(set_current(this)) + { + glEnable(GL_SCISSOR_TEST); + glScissor(left, bottom, width, height); + } } -void depth_func(Predicate func) +void ScissorTest::unbind() { - glDepthFunc(func); + if(set_current(0)) + glDisable(GL_SCISSOR_TEST); } } // namespace GL