Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 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 | |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 27 | Texture::Texture() |
| 28 | : id(0) |
| 29 | , generation(0) |
| 30 | , blend(false) |
| 31 | , width(0) |
| 32 | , height(0) |
| 33 | , cleanup(false) |
| 34 | , bitmapSize(0) |
| 35 | , mipMap(false) |
| 36 | , uvMapper(nullptr) |
| 37 | , isInUse(false) |
| 38 | , mWrapS(GL_CLAMP_TO_EDGE) |
| 39 | , mWrapT(GL_CLAMP_TO_EDGE) |
| 40 | , mMinFilter(GL_NEAREST) |
| 41 | , mMagFilter(GL_NEAREST) |
| 42 | , mFirstFilter(true) |
| 43 | , mFirstWrap(true) |
| 44 | , mCaches(Caches::getInstance()) { |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 47 | Texture::Texture(Caches& caches) |
| 48 | : id(0) |
| 49 | , generation(0) |
| 50 | , blend(false) |
| 51 | , width(0) |
| 52 | , height(0) |
| 53 | , cleanup(false) |
| 54 | , bitmapSize(0) |
| 55 | , mipMap(false) |
| 56 | , uvMapper(nullptr) |
| 57 | , isInUse(false) |
| 58 | , mWrapS(GL_CLAMP_TO_EDGE) |
| 59 | , mWrapT(GL_CLAMP_TO_EDGE) |
| 60 | , mMinFilter(GL_NEAREST) |
| 61 | , mMagFilter(GL_NEAREST) |
| 62 | , mFirstFilter(true) |
| 63 | , mFirstWrap(true) |
| 64 | , mCaches(caches) { |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void Texture::setWrapST(GLenum wrapS, GLenum wrapT, bool bindTexture, bool force, |
| 68 | GLenum renderTarget) { |
| 69 | |
| 70 | if (mFirstWrap || force || wrapS != mWrapS || wrapT != mWrapT) { |
| 71 | mFirstWrap = false; |
| 72 | |
| 73 | mWrapS = wrapS; |
| 74 | mWrapT = wrapT; |
| 75 | |
| 76 | if (bindTexture) { |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 77 | mCaches.textureState().bindTexture(renderTarget, id); |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | glTexParameteri(renderTarget, GL_TEXTURE_WRAP_S, wrapS); |
| 81 | glTexParameteri(renderTarget, GL_TEXTURE_WRAP_T, wrapT); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | void Texture::setFilterMinMag(GLenum min, GLenum mag, bool bindTexture, bool force, |
| 86 | GLenum renderTarget) { |
| 87 | |
| 88 | if (mFirstFilter || force || min != mMinFilter || mag != mMagFilter) { |
| 89 | mFirstFilter = false; |
| 90 | |
| 91 | mMinFilter = min; |
| 92 | mMagFilter = mag; |
| 93 | |
| 94 | if (bindTexture) { |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 95 | mCaches.textureState().bindTexture(renderTarget, id); |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | if (mipMap && min == GL_LINEAR) min = GL_LINEAR_MIPMAP_LINEAR; |
| 99 | |
| 100 | glTexParameteri(renderTarget, GL_TEXTURE_MIN_FILTER, min); |
| 101 | glTexParameteri(renderTarget, GL_TEXTURE_MAG_FILTER, mag); |
| 102 | } |
| 103 | } |
| 104 | |
Romain Guy | be1b127 | 2013-06-06 14:02:54 -0700 | [diff] [blame] | 105 | void Texture::deleteTexture() const { |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 106 | mCaches.textureState().deleteTexture(id); |
Romain Guy | be1b127 | 2013-06-06 14:02:54 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 109 | }; // namespace uirenderer |
| 110 | }; // namespace android |