Stencil.cpp revision f7e52d92b41adf460089625ea47bfea2ed7e6296
1/* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#include <GLES2/gl2.h> 18 19#include "Properties.h" 20#include "Stencil.h" 21 22namespace android { 23namespace uirenderer { 24 25Stencil::Stencil(): mState(kDisabled) { 26} 27 28uint32_t Stencil::getStencilSize() { 29 return STENCIL_BUFFER_SIZE; 30} 31 32void Stencil::clear() { 33 glClearStencil(0); 34 glClear(GL_STENCIL_BUFFER_BIT); 35} 36 37void Stencil::enableTest() { 38 if (mState != kTest) { 39 enable(); 40 glStencilFunc(GL_EQUAL, 0x0, 0x1); 41 // We only want to test, let's keep everything 42 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); 43 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 44 mState = kTest; 45 } 46} 47 48void Stencil::enableWrite() { 49 if (mState != kWrite) { 50 enable(); 51 glStencilFunc(GL_ALWAYS, 0x1, 0x1); 52 // The test always passes so the first two values are meaningless 53 glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); 54 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 55 mState = kWrite; 56 } 57} 58 59void Stencil::enable() { 60 if (!mState == kDisabled) { 61 glEnable(GL_STENCIL_TEST); 62 } 63} 64 65void Stencil::disable() { 66 if (mState != kDisabled) { 67 glDisable(GL_STENCIL_TEST); 68 mState = kDisabled; 69 } 70} 71 72}; // namespace uirenderer 73}; // namespace android 74