blob: 00b1cd27fc7beb9a02d6b9b62f951d48ffc13723 [file] [log] [blame]
Mathias Agopian875d8e12013-06-07 15:35:48 -07001/*
2 * Copyright 2013 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 <GLES/gl.h>
18
19#include <cutils/compiler.h>
20
21#include "GLES10RenderEngine.h"
22
23// ---------------------------------------------------------------------------
24namespace android {
25// ---------------------------------------------------------------------------
26
27GLES10RenderEngine::~GLES10RenderEngine() {
28}
29
30void GLES10RenderEngine::setupLayerBlending(
Dan Stoza9e56aa02015-11-02 13:00:03 -080031 bool premultipliedAlpha, bool opaque, float alpha) {
Mathias Agopian875d8e12013-06-07 15:35:48 -070032 // OpenGL ES 1.0 doesn't support texture combiners.
33 // This path doesn't properly handle opaque layers that have non-opaque
34 // alpha values. The alpha channel will be copied into the framebuffer or
35 // screenshot, so if the framebuffer or screenshot is blended on top of
36 // something else, whatever is below the window will incorrectly show
37 // through.
Dan Stoza9e56aa02015-11-02 13:00:03 -080038 if (CC_UNLIKELY(alpha < 1.0f)) {
39 if (premultipliedAlpha) {
40 glColor4f(alpha, alpha, alpha, alpha);
41 } else {
42 glColor4f(1.0f, 1.0f, 1.0f, alpha);
43 }
Mathias Agopian875d8e12013-06-07 15:35:48 -070044 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
45 } else {
46 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
47 }
48
Dan Stoza9e56aa02015-11-02 13:00:03 -080049 if (alpha < 1.0f || !opaque) {
Mathias Agopian875d8e12013-06-07 15:35:48 -070050 glEnable(GL_BLEND);
51 glBlendFunc(premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA,
52 GL_ONE_MINUS_SRC_ALPHA);
53 } else {
54 glDisable(GL_BLEND);
55 }
56}
57
58// ---------------------------------------------------------------------------
59}; // namespace android
60// ---------------------------------------------------------------------------