Texture.h revision 8aa195d7081b889f3a7b1f426cbd8556377aae5e
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#ifndef ANDROID_HWUI_TEXTURE_H 18#define ANDROID_HWUI_TEXTURE_H 19 20#include <GLES2/gl2.h> 21 22namespace android { 23namespace uirenderer { 24 25class Caches; 26class UvMapper; 27 28/** 29 * Represents an OpenGL texture. 30 */ 31class Texture { 32public: 33 Texture(); 34 Texture(Caches& caches); 35 36 virtual ~Texture() { } 37 38 inline void setWrap(GLenum wrap, bool bindTexture = false, bool force = false, 39 GLenum renderTarget = GL_TEXTURE_2D) { 40 setWrapST(wrap, wrap, bindTexture, force, renderTarget); 41 } 42 43 virtual void setWrapST(GLenum wrapS, GLenum wrapT, bool bindTexture = false, 44 bool force = false, GLenum renderTarget = GL_TEXTURE_2D); 45 46 inline void setFilter(GLenum filter, bool bindTexture = false, bool force = false, 47 GLenum renderTarget = GL_TEXTURE_2D) { 48 setFilterMinMag(filter, filter, bindTexture, force, renderTarget); 49 } 50 51 virtual void setFilterMinMag(GLenum min, GLenum mag, bool bindTexture = false, 52 bool force = false, GLenum renderTarget = GL_TEXTURE_2D); 53 54 /** 55 * Name of the texture. 56 */ 57 GLuint id; 58 /** 59 * Generation of the backing bitmap, 60 */ 61 uint32_t generation; 62 /** 63 * Indicates whether the texture requires blending. 64 */ 65 bool blend; 66 /** 67 * Width of the backing bitmap. 68 */ 69 uint32_t width; 70 /** 71 * Height of the backing bitmap. 72 */ 73 uint32_t height; 74 /** 75 * Indicates whether this texture should be cleaned up after use. 76 */ 77 bool cleanup; 78 /** 79 * Optional, size of the original bitmap. 80 */ 81 uint32_t bitmapSize; 82 /** 83 * Indicates whether this texture will use trilinear filtering. 84 */ 85 bool mipMap; 86 87 /** 88 * Optional, pointer to a texture coordinates mapper. 89 */ 90 const UvMapper* uvMapper; 91 92private: 93 /** 94 * Last wrap modes set on this texture. Defaults to GL_CLAMP_TO_EDGE. 95 */ 96 GLenum mWrapS; 97 GLenum mWrapT; 98 99 /** 100 * Last filters set on this texture. Defaults to GL_NEAREST. 101 */ 102 GLenum mMinFilter; 103 GLenum mMagFilter; 104 105 bool mFirstFilter; 106 bool mFirstWrap; 107 108 Caches& mCaches; 109}; // struct Texture 110 111class 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 125}; // namespace uirenderer 126}; // namespace android 127 128#endif // ANDROID_HWUI_TEXTURE_H 129