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: |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 33 | /** |
| 34 | * Returns the desired size for the stencil buffer. If the returned value |
| 35 | * is 0, then no stencil buffer is required. |
| 36 | */ |
John Reck | 23b797a | 2014-01-03 18:08:34 -0800 | [diff] [blame] | 37 | ANDROID_API static uint8_t getStencilSize(); |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 38 | |
Chris Craik | e145013 | 2015-04-28 17:55:50 -0700 | [diff] [blame] | 39 | static GLenum getLayerStencilFormat(); |
Romain Guy | 3bbacf2 | 2013-02-06 16:51:04 -0800 | [diff] [blame] | 40 | |
| 41 | /** |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 42 | * Clears the stencil buffer. |
| 43 | */ |
| 44 | void clear(); |
| 45 | |
| 46 | /** |
Rob Tsuk | 487a92c | 2015-01-06 13:22:54 -0800 | [diff] [blame] | 47 | * Enables stencil test. When the stencil test is enabled the stencil buffer is not written |
| 48 | * into. An increment threshold of zero causes the stencil to use a constant reference value |
| 49 | * and GL_EQUAL for the test. A non-zero increment threshold causes the stencil to use that |
| 50 | * value as the reference value and GL_EQUAL for the test. |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 51 | */ |
Rob Tsuk | 487a92c | 2015-01-06 13:22:54 -0800 | [diff] [blame] | 52 | void enableTest(int incrementThreshold); |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 53 | |
| 54 | /** |
| 55 | * Enables stencil write. When stencil write is enabled, the stencil |
| 56 | * test always succeeds and the value 0x1 is written in the stencil |
Rob Tsuk | 487a92c | 2015-01-06 13:22:54 -0800 | [diff] [blame] | 57 | * buffer for each fragment. An increment threshold of zero causes the stencil to use a constant |
| 58 | * reference value and GL_EQUAL for the test. A non-zero increment threshold causes the stencil |
| 59 | * 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] | 60 | */ |
Rob Tsuk | 487a92c | 2015-01-06 13:22:54 -0800 | [diff] [blame] | 61 | void enableWrite(int incrementThreshold); |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 62 | |
| 63 | /** |
Romain Guy | 7c450aa | 2012-09-21 19:15:00 -0700 | [diff] [blame] | 64 | * The test passes only when equal to the specified value. |
| 65 | */ |
| 66 | void enableDebugTest(GLint value, bool greater = false); |
| 67 | |
| 68 | /** |
| 69 | * Used for debugging. The stencil test always passes and increments. |
| 70 | */ |
| 71 | void enableDebugWrite(); |
| 72 | |
| 73 | /** |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 74 | * Disables stencil test and write. |
| 75 | */ |
| 76 | void disable(); |
| 77 | |
| 78 | /** |
| 79 | * Indicates whether either test or write is enabled. |
| 80 | */ |
| 81 | bool isEnabled() { |
Chris Craik | b9ce116d | 2015-08-20 15:14:06 -0700 | [diff] [blame^] | 82 | return mState != StencilState::Disabled; |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Romain Guy | 3ff0bfd | 2013-02-25 14:15:37 -0800 | [diff] [blame] | 85 | /** |
| 86 | * Indicates whether testing only is enabled. |
| 87 | */ |
| 88 | bool isTestEnabled() { |
Chris Craik | b9ce116d | 2015-08-20 15:14:06 -0700 | [diff] [blame^] | 89 | return mState == StencilState::Test; |
Romain Guy | 3ff0bfd | 2013-02-25 14:15:37 -0800 | [diff] [blame] | 90 | } |
| 91 | |
Chris Craik | 2ab95d7 | 2015-02-06 15:25:51 -0800 | [diff] [blame] | 92 | bool isWriteEnabled() { |
Chris Craik | b9ce116d | 2015-08-20 15:14:06 -0700 | [diff] [blame^] | 93 | return mState == StencilState::Write; |
Chris Craik | 2ab95d7 | 2015-02-06 15:25:51 -0800 | [diff] [blame] | 94 | } |
| 95 | |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 96 | void dump(); |
| 97 | |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 98 | private: |
Chris Craik | b9ce116d | 2015-08-20 15:14:06 -0700 | [diff] [blame^] | 99 | enum class StencilState { |
| 100 | Disabled, |
| 101 | Test, |
| 102 | Write |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
Chris Craik | b9ce116d | 2015-08-20 15:14:06 -0700 | [diff] [blame^] | 105 | void enable(); |
| 106 | StencilState mState = StencilState::Disabled; |
Romain Guy | 0baaac5 | 2012-08-31 20:31:01 -0700 | [diff] [blame] | 107 | |
| 108 | }; // class Stencil |
| 109 | |
| 110 | }; // namespace uirenderer |
| 111 | }; // namespace android |
| 112 | |
| 113 | #endif // ANDROID_HWUI_STENCIL_H |