Caches.cpp revision 9bca4793a33d2714b306d69ceb870925a588fe71
1/*
2 * Copyright (C) 2010 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#define LOG_TAG "OpenGLRenderer"
18
19#include "Caches.h"
20
21namespace android {
22
23#ifdef USE_OPENGL_RENDERER
24using namespace uirenderer;
25ANDROID_SINGLETON_STATIC_INSTANCE(Caches);
26#endif
27
28namespace uirenderer {
29
30///////////////////////////////////////////////////////////////////////////////
31// Constructors/destructor
32///////////////////////////////////////////////////////////////////////////////
33
34Caches::Caches(): Singleton<Caches>(), blend(false), lastSrcMode(GL_ZERO),
35        lastDstMode(GL_ZERO), currentProgram(NULL) {
36    GLint maxTextureUnits;
37    glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxTextureUnits);
38    if (maxTextureUnits < REQUIRED_TEXTURE_UNITS_COUNT) {
39        LOGW("At least %d texture units are required!", REQUIRED_TEXTURE_UNITS_COUNT);
40    }
41
42    glGenBuffers(1, &meshBuffer);
43    glBindBuffer(GL_ARRAY_BUFFER, meshBuffer);
44    glBufferData(GL_ARRAY_BUFFER, sizeof(gMeshVertices), gMeshVertices, GL_STATIC_DRAW);
45
46    mCurrentBuffer = meshBuffer;
47}
48
49/**
50 * Binds the VBO used to render simple textured quads.
51 */
52void Caches::bindMeshBuffer() {
53    bindMeshBuffer(meshBuffer);
54}
55
56/**
57 * Binds the specified VBO.
58 */
59void Caches::bindMeshBuffer(const GLuint buffer) {
60    if (mCurrentBuffer != buffer) {
61        glBindBuffer(GL_ARRAY_BUFFER, buffer);
62        mCurrentBuffer = buffer;
63    }
64}
65
66/**
67 * Unbinds the VBO used to render simple textured quads.
68 */
69void Caches::unbindMeshBuffer() {
70    if (mCurrentBuffer) {
71        glBindBuffer(GL_ARRAY_BUFFER, 0);
72        mCurrentBuffer = 0;
73    }
74}
75
76}; // namespace uirenderer
77}; // namespace android
78