blob: 32618230bbf66b930e9479dd85303e06bea1267f [file] [log] [blame]
Romain Guy0baaac52012-08-31 20:31:01 -07001/*
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 Guy3bbacf22013-02-06 16:51:04 -080020#include <GLES2/gl2.h>
21
Romain Guy0baaac52012-08-31 20:31:01 -070022#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 */
John Reck23b797a2014-01-03 18:08:34 -080039 ANDROID_API static uint8_t getStencilSize();
Romain Guy0baaac52012-08-31 20:31:01 -070040
Chris Craike1450132015-04-28 17:55:50 -070041 static GLenum getLayerStencilFormat();
Romain Guy3bbacf22013-02-06 16:51:04 -080042
43 /**
Romain Guy0baaac52012-08-31 20:31:01 -070044 * Clears the stencil buffer.
45 */
46 void clear();
47
48 /**
Rob Tsuk487a92c2015-01-06 13:22:54 -080049 * 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 Guy0baaac52012-08-31 20:31:01 -070053 */
Rob Tsuk487a92c2015-01-06 13:22:54 -080054 void enableTest(int incrementThreshold);
Romain Guy0baaac52012-08-31 20:31:01 -070055
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 Tsuk487a92c2015-01-06 13:22:54 -080059 * 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 Guy0baaac52012-08-31 20:31:01 -070062 */
Rob Tsuk487a92c2015-01-06 13:22:54 -080063 void enableWrite(int incrementThreshold);
Romain Guy0baaac52012-08-31 20:31:01 -070064
65 /**
Romain Guy7c450aa2012-09-21 19:15:00 -070066 * 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 Guy0baaac52012-08-31 20:31:01 -070076 * 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 Guy3ff0bfd2013-02-25 14:15:37 -080087 /**
88 * Indicates whether testing only is enabled.
89 */
90 bool isTestEnabled() {
91 return mState == kTest;
92 }
93
Chris Craik2ab95d72015-02-06 15:25:51 -080094 bool isWriteEnabled() {
95 return mState == kWrite;
96 }
97
Chris Craik117bdbc2015-02-05 10:12:38 -080098 void dump();
99
Romain Guy0baaac52012-08-31 20:31:01 -0700100private:
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