blob: c5e5186866d28b74f83b1c914777dc05a5c0b424 [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
45 /**
Romain Guy3bbacf22013-02-06 16:51:04 -080046 * Returns the smallest stencil format accepted by render buffers.
47 */
48 static GLenum getSmallestStencilFormat();
49
50 /**
Romain Guy0baaac52012-08-31 20:31:01 -070051 * Clears the stencil buffer.
52 */
53 void clear();
54
55 /**
56 * Enables stencil test. When the stencil test is enabled the stencil
57 * buffer is not written into.
58 */
59 void enableTest();
60
61 /**
62 * Enables stencil write. When stencil write is enabled, the stencil
63 * test always succeeds and the value 0x1 is written in the stencil
64 * buffer for each fragment.
65 */
66 void enableWrite();
67
68 /**
Romain Guy7c450aa2012-09-21 19:15:00 -070069 * The test passes only when equal to the specified value.
70 */
71 void enableDebugTest(GLint value, bool greater = false);
72
73 /**
74 * Used for debugging. The stencil test always passes and increments.
75 */
76 void enableDebugWrite();
77
78 /**
Romain Guy0baaac52012-08-31 20:31:01 -070079 * Disables stencil test and write.
80 */
81 void disable();
82
83 /**
84 * Indicates whether either test or write is enabled.
85 */
86 bool isEnabled() {
87 return mState != kDisabled;
88 }
89
Romain Guy3ff0bfd2013-02-25 14:15:37 -080090 /**
91 * Indicates whether testing only is enabled.
92 */
93 bool isTestEnabled() {
94 return mState == kTest;
95 }
96
Romain Guy0baaac52012-08-31 20:31:01 -070097private:
98 void enable();
99
100 enum StencilState {
101 kDisabled,
102 kTest,
103 kWrite
104 };
105
106 StencilState mState;
107
108}; // class Stencil
109
110}; // namespace uirenderer
111}; // namespace android
112
113#endif // ANDROID_HWUI_STENCIL_H