blob: 9a47568f55be9cb55646129f60be81c782d85505 [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(
31 bool premultipliedAlpha, bool opaque, int alpha) {
32 // 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.
38 if (CC_UNLIKELY(alpha < 0xFF)) {
39 GLfloat floatAlpha = alpha * (1.0f / 255.0f);
40 if (premultipliedAlpha) {
41 glColor4f(floatAlpha, floatAlpha, floatAlpha, floatAlpha);
42 } else {
43 glColor4f(1.0f, 1.0f, 1.0f, floatAlpha);
44 }
45 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
46 } else {
47 glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
48 }
49
50 if (alpha < 0xFF || !opaque) {
51 glEnable(GL_BLEND);
52 glBlendFunc(premultipliedAlpha ? GL_ONE : GL_SRC_ALPHA,
53 GL_ONE_MINUS_SRC_ALPHA);
54 } else {
55 glDisable(GL_BLEND);
56 }
57}
58
59// ---------------------------------------------------------------------------
60}; // namespace android
61// ---------------------------------------------------------------------------