blob: 3a8f8ebad48d8bf7c13ffffcabc8f8c1984b2634 [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
20#ifndef LOG_TAG
21 #define LOG_TAG "OpenGLRenderer"
22#endif
23
Romain Guy3bbacf22013-02-06 16:51:04 -080024#include <GLES2/gl2.h>
25
Romain Guy0baaac52012-08-31 20:31:01 -070026#include <cutils/compiler.h>
27
28namespace android {
29namespace uirenderer {
30
31///////////////////////////////////////////////////////////////////////////////
32// Stencil buffer management
33///////////////////////////////////////////////////////////////////////////////
34
35class ANDROID_API Stencil {
36public:
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 Reck23b797a2014-01-03 18:08:34 -080043 ANDROID_API static uint8_t getStencilSize();
Romain Guy0baaac52012-08-31 20:31:01 -070044
Chris Craike1450132015-04-28 17:55:50 -070045 static GLenum getLayerStencilFormat();
Romain Guy3bbacf22013-02-06 16:51:04 -080046
47 /**
Romain Guy0baaac52012-08-31 20:31:01 -070048 * Clears the stencil buffer.
49 */
50 void clear();
51
52 /**
Rob Tsuk487a92c2015-01-06 13:22:54 -080053 * Enables stencil test. When the stencil test is enabled the stencil buffer is not written
54 * into. An increment threshold of zero causes the stencil to use a constant reference value
55 * and GL_EQUAL for the test. A non-zero increment threshold causes the stencil to use that
56 * value as the reference value and GL_EQUAL for the test.
Romain Guy0baaac52012-08-31 20:31:01 -070057 */
Rob Tsuk487a92c2015-01-06 13:22:54 -080058 void enableTest(int incrementThreshold);
Romain Guy0baaac52012-08-31 20:31:01 -070059
60 /**
61 * Enables stencil write. When stencil write is enabled, the stencil
62 * test always succeeds and the value 0x1 is written in the stencil
Rob Tsuk487a92c2015-01-06 13:22:54 -080063 * buffer for each fragment. An increment threshold of zero causes the stencil to use a constant
64 * reference value and GL_EQUAL for the test. A non-zero increment threshold causes the stencil
65 * to use that value as the reference value and GL_EQUAL for the test.
Romain Guy0baaac52012-08-31 20:31:01 -070066 */
Rob Tsuk487a92c2015-01-06 13:22:54 -080067 void enableWrite(int incrementThreshold);
Romain Guy0baaac52012-08-31 20:31:01 -070068
69 /**
Romain Guy7c450aa2012-09-21 19:15:00 -070070 * The test passes only when equal to the specified value.
71 */
72 void enableDebugTest(GLint value, bool greater = false);
73
74 /**
75 * Used for debugging. The stencil test always passes and increments.
76 */
77 void enableDebugWrite();
78
79 /**
Romain Guy0baaac52012-08-31 20:31:01 -070080 * Disables stencil test and write.
81 */
82 void disable();
83
84 /**
85 * Indicates whether either test or write is enabled.
86 */
87 bool isEnabled() {
88 return mState != kDisabled;
89 }
90
Romain Guy3ff0bfd2013-02-25 14:15:37 -080091 /**
92 * Indicates whether testing only is enabled.
93 */
94 bool isTestEnabled() {
95 return mState == kTest;
96 }
97
Chris Craik2ab95d72015-02-06 15:25:51 -080098 bool isWriteEnabled() {
99 return mState == kWrite;
100 }
101
Chris Craik117bdbc2015-02-05 10:12:38 -0800102 void dump();
103
Romain Guy0baaac52012-08-31 20:31:01 -0700104private:
105 void enable();
106
107 enum StencilState {
108 kDisabled,
109 kTest,
110 kWrite
111 };
112
113 StencilState mState;
114
115}; // class Stencil
116
117}; // namespace uirenderer
118}; // namespace android
119
120#endif // ANDROID_HWUI_STENCIL_H