Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 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 | |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 20 | #include <GLES2/gl2.h> |
| 21 | |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 22 | #include <cutils/compiler.h> |
| 23 | |
| 24 | namespace android { |
| 25 | namespace uirenderer { |
| 26 | |
| 27 | /////////////////////////////////////////////////////////////////////////////// |
| 28 | // Stencil buffer management |
| 29 | /////////////////////////////////////////////////////////////////////////////// |
| 30 | |
| 31 | class ANDROID_API Stencil { |
| 32 | public: |
| 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 | */ |
John Reck | 23b797a | 2014-01-03 18:08:34 -0800 | [diff] [blame] | 39 | ANDROID_API static uint8_t getStencilSize(); |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 40 | |
Chris Craik | e145013 | 2015-04-28 17:55:50 -0700 | [diff] [blame] | 41 | static GLenum getLayerStencilFormat(); |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 42 | |
| 43 | /** |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 44 | * Clears the stencil buffer. |
| 45 | */ |
| 46 | void clear(); |
| 47 | |
| 48 | /** |
Rob Tsuk | 487a92c | 2015-01-06 13:22:54 -0800 | [diff] [blame] | 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. |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 53 | */ |
Rob Tsuk | 487a92c | 2015-01-06 13:22:54 -0800 | [diff] [blame] | 54 | void enableTest(int incrementThreshold); |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 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 |
Rob Tsuk | 487a92c | 2015-01-06 13:22:54 -0800 | [diff] [blame] | 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. |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 62 | */ |
Rob Tsuk | 487a92c | 2015-01-06 13:22:54 -0800 | [diff] [blame] | 63 | void enableWrite(int incrementThreshold); |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 64 | |
| 65 | /** |
Romain Guy | 7c450aa | 2012-09-21 19:15:00 -0700 | [diff] [blame] | 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 | /** |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 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 | |
Romain Guy | 3ff0bfd | 2013-02-25 14:15:37 -0800 | [diff] [blame] | 87 | /** |
| 88 | * Indicates whether testing only is enabled. |
| 89 | */ |
| 90 | bool isTestEnabled() { |
| 91 | return mState == kTest; |
| 92 | } |
| 93 | |
Chris Craik | 2ab95d7 | 2015-02-06 15:25:51 -0800 | [diff] [blame] | 94 | bool isWriteEnabled() { |
| 95 | return mState == kWrite; |
| 96 | } |
| 97 | |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 98 | void dump(); |
| 99 | |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 100 | private: |
| 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 |