blob: 95f372344ee4cfba5daf13a4788e4dd2187d2344 [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:
Romain Guy0baaac52012-08-31 20:31:01 -070033 /**
34 * Returns the desired size for the stencil buffer. If the returned value
35 * is 0, then no stencil buffer is required.
36 */
John Reck23b797a2014-01-03 18:08:34 -080037 ANDROID_API static uint8_t getStencilSize();
Romain Guy0baaac52012-08-31 20:31:01 -070038
Chris Craike1450132015-04-28 17:55:50 -070039 static GLenum getLayerStencilFormat();
Romain Guy3bbacf22013-02-06 16:51:04 -080040
41 /**
Romain Guy0baaac52012-08-31 20:31:01 -070042 * Clears the stencil buffer.
43 */
44 void clear();
45
46 /**
Rob Tsuk487a92c2015-01-06 13:22:54 -080047 * 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 Guy0baaac52012-08-31 20:31:01 -070051 */
Rob Tsuk487a92c2015-01-06 13:22:54 -080052 void enableTest(int incrementThreshold);
Romain Guy0baaac52012-08-31 20:31:01 -070053
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 Tsuk487a92c2015-01-06 13:22:54 -080057 * 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 Guy0baaac52012-08-31 20:31:01 -070060 */
Rob Tsuk487a92c2015-01-06 13:22:54 -080061 void enableWrite(int incrementThreshold);
Romain Guy0baaac52012-08-31 20:31:01 -070062
63 /**
Romain Guy7c450aa2012-09-21 19:15:00 -070064 * 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 Guy0baaac52012-08-31 20:31:01 -070074 * Disables stencil test and write.
75 */
76 void disable();
77
78 /**
79 * Indicates whether either test or write is enabled.
80 */
John Reck1bcacfd2017-11-03 10:12:19 -070081 bool isEnabled() { return mState != StencilState::Disabled; }
Romain Guy0baaac52012-08-31 20:31:01 -070082
Romain Guy3ff0bfd2013-02-25 14:15:37 -080083 /**
84 * Indicates whether testing only is enabled.
85 */
John Reck1bcacfd2017-11-03 10:12:19 -070086 bool isTestEnabled() { return mState == StencilState::Test; }
Romain Guy3ff0bfd2013-02-25 14:15:37 -080087
John Reck1bcacfd2017-11-03 10:12:19 -070088 bool isWriteEnabled() { return mState == StencilState::Write; }
Chris Craik2ab95d72015-02-06 15:25:51 -080089
Chris Craik117bdbc2015-02-05 10:12:38 -080090 void dump();
91
Romain Guy0baaac52012-08-31 20:31:01 -070092private:
John Reck1bcacfd2017-11-03 10:12:19 -070093 enum class StencilState { Disabled, Test, Write };
Romain Guy0baaac52012-08-31 20:31:01 -070094
Chris Craikb9ce116d2015-08-20 15:14:06 -070095 void enable();
96 StencilState mState = StencilState::Disabled;
Romain Guy0baaac52012-08-31 20:31:01 -070097
John Reck1bcacfd2017-11-03 10:12:19 -070098}; // class Stencil
Romain Guy0baaac52012-08-31 20:31:01 -070099
John Reck1bcacfd2017-11-03 10:12:19 -0700100}; // namespace uirenderer
101}; // namespace android
Romain Guy0baaac52012-08-31 20:31:01 -0700102
John Reck1bcacfd2017-11-03 10:12:19 -0700103#endif // ANDROID_HWUI_STENCIL_H