blob: 0994d82f8661b8b257189db9e86a21d80ab13b0b [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 Guy746b7402010-10-26 16:27:31 -070046 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize);
47
Romain Guy9bca4792010-10-25 18:42:25 -070048 mCurrentBuffer = meshBuffer;
Chet Haasedd78cca2010-10-22 18:59:26 -070049}
50
51/**
52 * Binds the VBO used to render simple textured quads.
53 */
54void Caches::bindMeshBuffer() {
55 bindMeshBuffer(meshBuffer);
56}
57
58/**
59 * Binds the specified VBO.
60 */
61void Caches::bindMeshBuffer(const GLuint buffer) {
Romain Guy9bca4792010-10-25 18:42:25 -070062 if (mCurrentBuffer != buffer) {
Chet Haasedd78cca2010-10-22 18:59:26 -070063 glBindBuffer(GL_ARRAY_BUFFER, buffer);
Romain Guy9bca4792010-10-25 18:42:25 -070064 mCurrentBuffer = buffer;
Chet Haasedd78cca2010-10-22 18:59:26 -070065 }
66}
67
68/**
69 * Unbinds the VBO used to render simple textured quads.
70 */
71void Caches::unbindMeshBuffer() {
Romain Guy9bca4792010-10-25 18:42:25 -070072 if (mCurrentBuffer) {
Chet Haasedd78cca2010-10-22 18:59:26 -070073 glBindBuffer(GL_ARRAY_BUFFER, 0);
Romain Guy9bca4792010-10-25 18:42:25 -070074 mCurrentBuffer = 0;
Chet Haasedd78cca2010-10-22 18:59:26 -070075 }
76}
77
78}; // namespace uirenderer
79}; // namespace android