blob: 512f5cf0d9a382d0602fd1b488d3e3a3aefc299e [file] [log] [blame]
Romain Guy8aa195d2013-06-04 18:00:09 -07001/*
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
24namespace android {
25namespace uirenderer {
26
Chris Craik44eb2c02015-01-29 09:45:09 -080027Texture::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 Guy8aa195d2013-06-04 18:00:09 -070045}
46
Chris Craik44eb2c02015-01-29 09:45:09 -080047Texture::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 Guy8aa195d2013-06-04 18:00:09 -070065}
66
67void 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 Craik44eb2c02015-01-29 09:45:09 -080077 mCaches.textureState().bindTexture(renderTarget, id);
Romain Guy8aa195d2013-06-04 18:00:09 -070078 }
79
80 glTexParameteri(renderTarget, GL_TEXTURE_WRAP_S, wrapS);
81 glTexParameteri(renderTarget, GL_TEXTURE_WRAP_T, wrapT);
82 }
83}
84
85void 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 Craik44eb2c02015-01-29 09:45:09 -080095 mCaches.textureState().bindTexture(renderTarget, id);
Romain Guy8aa195d2013-06-04 18:00:09 -070096 }
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 Guybe1b1272013-06-06 14:02:54 -0700105void Texture::deleteTexture() const {
Chris Craik44eb2c02015-01-29 09:45:09 -0800106 mCaches.textureState().deleteTexture(id);
Romain Guybe1b1272013-06-06 14:02:54 -0700107}
108
Romain Guy8aa195d2013-06-04 18:00:09 -0700109}; // namespace uirenderer
110}; // namespace android