Description.cpp revision 3f84483382be2d528918cc1a6fbc6a7d68e0b181
1/*
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 <stdint.h>
18#include <string.h>
19
20#include <utils/TypeHelpers.h>
21
22#include <GLES2/gl2.h>
23#include <GLES2/gl2ext.h>
24
25#include "Description.h"
26
27namespace android {
28
29Description::Description() :
30    mUniformsDirty(true) {
31    mPlaneAlpha = 1.0f;
32    mPremultipliedAlpha = true;
33    mOpaque = true;
34    mTextureTarget = GL_TEXTURE_EXTERNAL_OES;
35
36    const GLfloat m[16] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 };
37    memset(mColor, 0, sizeof(mColor));
38    memcpy(mProjectionMatrix, m, sizeof(mProjectionMatrix));
39    memcpy(mTextureMatrix, m, sizeof(mTextureMatrix));
40}
41
42Description::~Description() {
43}
44
45void Description::setPlaneAlpha(GLclampf planeAlpha) {
46    if (planeAlpha != mPlaneAlpha) {
47        mUniformsDirty = true;
48        mPlaneAlpha = planeAlpha;
49    }
50}
51
52void Description::setPremultipliedAlpha(bool premultipliedAlpha) {
53    if (premultipliedAlpha != mPremultipliedAlpha) {
54        mPremultipliedAlpha = premultipliedAlpha;
55    }
56}
57
58void Description::setOpaque(bool opaque) {
59    if (opaque != mOpaque) {
60        mOpaque = opaque;
61    }
62}
63
64void Description::setTextureName(GLenum target, GLuint tname) {
65    if (target != mTextureTarget) {
66        mTextureTarget = target;
67    }
68    if (tname != mTextureName) {
69        mTextureName = tname;
70        mUniformsDirty = true;
71    }
72}
73
74void Description::disableTexture() {
75    if (mTextureTarget != 0) {
76        mTextureTarget = 0;
77    }
78    mTextureName = 0;
79}
80
81void Description::setColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) {
82    mColor[0] = red;
83    mColor[1] = green;
84    mColor[2] = blue;
85    mColor[3] = alpha;
86    mUniformsDirty = true;
87}
88
89void Description::setProjectionMatrix(GLfloat const* mtx) {
90    memcpy(mProjectionMatrix, mtx, sizeof(mProjectionMatrix));
91    mUniformsDirty = true;
92}
93
94void Description::setTextureMatrix(GLfloat const* mtx) {
95    memcpy(mTextureMatrix, mtx, sizeof(mTextureMatrix));
96    mUniformsDirty = true;
97}
98
99} /* namespace android */
100