blob: d249741f703b6d9e969b2935da66e95062432666 [file] [log] [blame]
Romain Guyce0537b2010-06-29 21:05:21 -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
Romain Guy5b3b3522010-10-27 18:57:51 -070017#ifndef ANDROID_HWUI_TEXTURE_H
18#define ANDROID_HWUI_TEXTURE_H
Romain Guyce0537b2010-06-29 21:05:21 -070019
20#include <GLES2/gl2.h>
21
22namespace android {
23namespace uirenderer {
24
Romain Guy8aa195d2013-06-04 18:00:09 -070025class Caches;
Romain Guy3b748a42013-04-17 18:54:38 -070026class UvMapper;
27
Romain Guyce0537b2010-06-29 21:05:21 -070028/**
29 * Represents an OpenGL texture.
30 */
Romain Guy8aa195d2013-06-04 18:00:09 -070031class Texture {
32public:
33 Texture();
34 Texture(Caches& caches);
Romain Guy9ace8f52011-07-07 20:50:11 -070035
Romain Guya404e162013-05-24 16:19:19 -070036 virtual ~Texture() { }
37
Romain Guy8aa195d2013-06-04 18:00:09 -070038 inline void setWrap(GLenum wrap, bool bindTexture = false, bool force = false,
Romain Guyd21b6e12011-11-30 20:21:23 -080039 GLenum renderTarget = GL_TEXTURE_2D) {
40 setWrapST(wrap, wrap, bindTexture, force, renderTarget);
41 }
42
Romain Guya404e162013-05-24 16:19:19 -070043 virtual void setWrapST(GLenum wrapS, GLenum wrapT, bool bindTexture = false,
Romain Guy8aa195d2013-06-04 18:00:09 -070044 bool force = false, GLenum renderTarget = GL_TEXTURE_2D);
Romain Guye3c26852011-07-25 16:36:01 -070045
Romain Guy8aa195d2013-06-04 18:00:09 -070046 inline void setFilter(GLenum filter, bool bindTexture = false, bool force = false,
Romain Guyd21b6e12011-11-30 20:21:23 -080047 GLenum renderTarget = GL_TEXTURE_2D) {
48 setFilterMinMag(filter, filter, bindTexture, force, renderTarget);
49 }
50
Romain Guya404e162013-05-24 16:19:19 -070051 virtual void setFilterMinMag(GLenum min, GLenum mag, bool bindTexture = false,
Romain Guy8aa195d2013-06-04 18:00:09 -070052 bool force = false, GLenum renderTarget = GL_TEXTURE_2D);
Romain Guy22158e12010-08-06 11:18:34 -070053
Romain Guyce0537b2010-06-29 21:05:21 -070054 /**
55 * Name of the texture.
56 */
57 GLuint id;
58 /**
Romain Guyfe880942010-06-30 16:05:32 -070059 * Generation of the backing bitmap,
60 */
61 uint32_t generation;
62 /**
Romain Guyce0537b2010-06-29 21:05:21 -070063 * Indicates whether the texture requires blending.
64 */
65 bool blend;
66 /**
67 * Width of the backing bitmap.
68 */
Romain Guy7d139ba2010-07-02 11:20:34 -070069 uint32_t width;
Romain Guyce0537b2010-06-29 21:05:21 -070070 /**
71 * Height of the backing bitmap.
72 */
Romain Guy7d139ba2010-07-02 11:20:34 -070073 uint32_t height;
Romain Guy22158e12010-08-06 11:18:34 -070074 /**
75 * Indicates whether this texture should be cleaned up after use.
76 */
77 bool cleanup;
Romain Guy9aaa8262010-09-08 15:15:43 -070078 /**
79 * Optional, size of the original bitmap.
80 */
81 uint32_t bitmapSize;
Romain Guy713e1bb2012-10-16 18:44:09 -070082 /**
83 * Indicates whether this texture will use trilinear filtering.
84 */
85 bool mipMap;
Romain Guy8164c2d2010-10-25 18:03:28 -070086
Romain Guy3b748a42013-04-17 18:54:38 -070087 /**
88 * Optional, pointer to a texture coordinates mapper.
89 */
90 const UvMapper* uvMapper;
91
Romain Guy713e1bb2012-10-16 18:44:09 -070092private:
Romain Guy8164c2d2010-10-25 18:03:28 -070093 /**
94 * Last wrap modes set on this texture. Defaults to GL_CLAMP_TO_EDGE.
95 */
Romain Guy8aa195d2013-06-04 18:00:09 -070096 GLenum mWrapS;
97 GLenum mWrapT;
Romain Guy9ace8f52011-07-07 20:50:11 -070098
99 /**
100 * Last filters set on this texture. Defaults to GL_NEAREST.
101 */
Romain Guy8aa195d2013-06-04 18:00:09 -0700102 GLenum mMinFilter;
103 GLenum mMagFilter;
Romain Guye3c26852011-07-25 16:36:01 -0700104
Romain Guy8aa195d2013-06-04 18:00:09 -0700105 bool mFirstFilter;
106 bool mFirstWrap;
107
108 Caches& mCaches;
Romain Guyce0537b2010-06-29 21:05:21 -0700109}; // struct Texture
110
Romain Guy22158e12010-08-06 11:18:34 -0700111class AutoTexture {
112public:
113 AutoTexture(const Texture* texture): mTexture(texture) { }
114 ~AutoTexture() {
115 if (mTexture && mTexture->cleanup) {
116 glDeleteTextures(1, &mTexture->id);
117 delete mTexture;
118 }
119 }
120
121private:
122 const Texture* mTexture;
123}; // class AutoTexture
124
Romain Guyce0537b2010-06-29 21:05:21 -0700125}; // namespace uirenderer
126}; // namespace android
127
Romain Guy5b3b3522010-10-27 18:57:51 -0700128#endif // ANDROID_HWUI_TEXTURE_H