Stencil.h revision 5a4690bf26932c0d6940e4af8516d920e09ae81a
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#ifndef ANDROID_HWUI_STENCIL_H 18#define ANDROID_HWUI_STENCIL_H 19 20#include <GLES2/gl2.h> 21 22#include <cutils/compiler.h> 23 24namespace android { 25namespace uirenderer { 26 27/////////////////////////////////////////////////////////////////////////////// 28// Stencil buffer management 29/////////////////////////////////////////////////////////////////////////////// 30 31class ANDROID_API Stencil { 32public: 33 Stencil(); 34 35 /** 36 * Returns the desired size for the stencil buffer. If the returned value 37 * is 0, then no stencil buffer is required. 38 */ 39 ANDROID_API static uint8_t getStencilSize(); 40 41 static GLenum getLayerStencilFormat(); 42 43 /** 44 * Clears the stencil buffer. 45 */ 46 void clear(); 47 48 /** 49 * Enables stencil test. When the stencil test is enabled the stencil buffer is not written 50 * into. An increment threshold of zero causes the stencil to use a constant reference value 51 * and GL_EQUAL for the test. A non-zero increment threshold causes the stencil to use that 52 * value as the reference value and GL_EQUAL for the test. 53 */ 54 void enableTest(int incrementThreshold); 55 56 /** 57 * Enables stencil write. When stencil write is enabled, the stencil 58 * test always succeeds and the value 0x1 is written in the stencil 59 * buffer for each fragment. An increment threshold of zero causes the stencil to use a constant 60 * reference value and GL_EQUAL for the test. A non-zero increment threshold causes the stencil 61 * to use that value as the reference value and GL_EQUAL for the test. 62 */ 63 void enableWrite(int incrementThreshold); 64 65 /** 66 * The test passes only when equal to the specified value. 67 */ 68 void enableDebugTest(GLint value, bool greater = false); 69 70 /** 71 * Used for debugging. The stencil test always passes and increments. 72 */ 73 void enableDebugWrite(); 74 75 /** 76 * Disables stencil test and write. 77 */ 78 void disable(); 79 80 /** 81 * Indicates whether either test or write is enabled. 82 */ 83 bool isEnabled() { 84 return mState != kDisabled; 85 } 86 87 /** 88 * Indicates whether testing only is enabled. 89 */ 90 bool isTestEnabled() { 91 return mState == kTest; 92 } 93 94 bool isWriteEnabled() { 95 return mState == kWrite; 96 } 97 98 void dump(); 99 100private: 101 void enable(); 102 103 enum StencilState { 104 kDisabled, 105 kTest, 106 kWrite 107 }; 108 109 StencilState mState; 110 111}; // class Stencil 112 113}; // namespace uirenderer 114}; // namespace android 115 116#endif // ANDROID_HWUI_STENCIL_H 117