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