1 /* 2 * Copyright (C) 2013 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 <utils/Log.h> 20 21 #include "Caches.h" 22 #include "Texture.h" 23 24 namespace android { 25 namespace uirenderer { 26 27 Texture::Texture(): id(0), generation(0), blend(false), width(0), height(0), 28 cleanup(false), bitmapSize(0), mipMap(false), uvMapper(NULL), 29 mWrapS(GL_CLAMP_TO_EDGE), mWrapT(GL_CLAMP_TO_EDGE), 30 mMinFilter(GL_NEAREST), mMagFilter(GL_NEAREST), 31 mFirstFilter(true), mFirstWrap(true), mCaches(Caches::getInstance()) { 32 } 33 34 Texture::Texture(Caches& caches): id(0), generation(0), blend(false), width(0), height(0), 35 cleanup(false), bitmapSize(0), mipMap(false), uvMapper(NULL), 36 mWrapS(GL_CLAMP_TO_EDGE), mWrapT(GL_CLAMP_TO_EDGE), 37 mMinFilter(GL_NEAREST), mMagFilter(GL_NEAREST), 38 mFirstFilter(true), mFirstWrap(true), mCaches(caches) { 39 } 40 41 void Texture::setWrapST(GLenum wrapS, GLenum wrapT, bool bindTexture, bool force, 42 GLenum renderTarget) { 43 44 if (mFirstWrap || force || wrapS != mWrapS || wrapT != mWrapT) { 45 mFirstWrap = false; 46 47 mWrapS = wrapS; 48 mWrapT = wrapT; 49 50 if (bindTexture) { 51 mCaches.bindTexture(renderTarget, id); 52 } 53 54 glTexParameteri(renderTarget, GL_TEXTURE_WRAP_S, wrapS); 55 glTexParameteri(renderTarget, GL_TEXTURE_WRAP_T, wrapT); 56 } 57 } 58 59 void Texture::setFilterMinMag(GLenum min, GLenum mag, bool bindTexture, bool force, 60 GLenum renderTarget) { 61 62 if (mFirstFilter || force || min != mMinFilter || mag != mMagFilter) { 63 mFirstFilter = false; 64 65 mMinFilter = min; 66 mMagFilter = mag; 67 68 if (bindTexture) { 69 mCaches.bindTexture(renderTarget, id); 70 } 71 72 if (mipMap && min == GL_LINEAR) min = GL_LINEAR_MIPMAP_LINEAR; 73 74 glTexParameteri(renderTarget, GL_TEXTURE_MIN_FILTER, min); 75 glTexParameteri(renderTarget, GL_TEXTURE_MAG_FILTER, mag); 76 } 77 } 78 79 void Texture::deleteTexture() const { 80 mCaches.deleteTexture(id); 81 } 82 83 }; // namespace uirenderer 84 }; // namespace android 85