blob: e0094d8245dbc5837a4070e420095a044d4a4f48 [file] [log] [blame]
Chet Haasedd78cca2010-10-22 18:59:26 -07001/*
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
Romain Guy9bca4792010-10-25 18:42:25 -070046 mCurrentBuffer = meshBuffer;
Chet Haasedd78cca2010-10-22 18:59:26 -070047}
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) {
Romain Guy9bca4792010-10-25 18:42:25 -070060 if (mCurrentBuffer != buffer) {
Chet Haasedd78cca2010-10-22 18:59:26 -070061 glBindBuffer(GL_ARRAY_BUFFER, buffer);
Romain Guy9bca4792010-10-25 18:42:25 -070062 mCurrentBuffer = buffer;
Chet Haasedd78cca2010-10-22 18:59:26 -070063 }
64}
65
66/**
67 * Unbinds the VBO used to render simple textured quads.
68 */
69void Caches::unbindMeshBuffer() {
Romain Guy9bca4792010-10-25 18:42:25 -070070 if (mCurrentBuffer) {
Chet Haasedd78cca2010-10-22 18:59:26 -070071 glBindBuffer(GL_ARRAY_BUFFER, 0);
Romain Guy9bca4792010-10-25 18:42:25 -070072 mCurrentBuffer = 0;
Chet Haasedd78cca2010-10-22 18:59:26 -070073 }
74}
75
76}; // namespace uirenderer
77}; // namespace android