blob: 84df82b7b08f41f7b1437d0458d9c6f13ca32a56 [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#include <GLES2/gl2.h>
18
19#include "Properties.h"
20#include "Stencil.h"
21
22namespace android {
23namespace uirenderer {
24
25Stencil::Stencil(): mState(kDisabled) {
26}
27
28uint32_t Stencil::getStencilSize() {
29 return STENCIL_BUFFER_SIZE;
30}
31
32void Stencil::clear() {
33 glClearStencil(0);
34 glClear(GL_STENCIL_BUFFER_BIT);
35}
36
37void Stencil::enableTest() {
38 if (mState != kTest) {
39 enable();
Romain Guy7c450aa2012-09-21 19:15:00 -070040 glStencilFunc(GL_EQUAL, 0x1, 0x1);
Romain Guy0baaac52012-08-31 20:31:01 -070041 // We only want to test, let's keep everything
42 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
Romain Guyf7e52d92012-09-21 15:06:52 -070043 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
Romain Guy0baaac52012-08-31 20:31:01 -070044 mState = kTest;
45 }
46}
47
48void Stencil::enableWrite() {
49 if (mState != kWrite) {
50 enable();
51 glStencilFunc(GL_ALWAYS, 0x1, 0x1);
52 // The test always passes so the first two values are meaningless
53 glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
Romain Guyf7e52d92012-09-21 15:06:52 -070054 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
Romain Guy0baaac52012-08-31 20:31:01 -070055 mState = kWrite;
56 }
57}
58
Romain Guy7c450aa2012-09-21 19:15:00 -070059void Stencil::enableDebugTest(GLint value, bool greater) {
60 enable();
61 glStencilFunc(greater ? GL_LESS : GL_EQUAL, value, 0xffffffff);
62 // We only want to test, let's keep everything
63 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
64 mState = kTest;
65}
66
67void Stencil::enableDebugWrite() {
68 if (mState != kWrite) {
69 enable();
70 glStencilFunc(GL_ALWAYS, 0x1, 0xffffffff);
71 // The test always passes so the first two values are meaningless
72 glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
73 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
74 mState = kWrite;
75 }
76}
77
Romain Guy0baaac52012-08-31 20:31:01 -070078void Stencil::enable() {
Romain Guy7c450aa2012-09-21 19:15:00 -070079 if (mState == kDisabled) {
Romain Guy0baaac52012-08-31 20:31:01 -070080 glEnable(GL_STENCIL_TEST);
81 }
82}
83
84void Stencil::disable() {
85 if (mState != kDisabled) {
86 glDisable(GL_STENCIL_TEST);
87 mState = kDisabled;
88 }
89}
90
91}; // namespace uirenderer
92}; // namespace android