• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 #ifndef RENDERSTATE_TEXTURESTATE_H
17 #define RENDERSTATE_TEXTURESTATE_H
18 
19 #include "Vertex.h"
20 
21 #include <GLES2/gl2.h>
22 #include <GLES2/gl2ext.h>
23 #include <SkXfermode.h>
24 #include <memory>
25 
26 namespace android {
27 namespace uirenderer {
28 
29 class TextureState {
30     friend class Caches; // TODO: move to RenderState
31 public:
32     /**
33      * Activate the specified texture unit. The texture unit must
34      * be specified using an integer number (0 for GL_TEXTURE0 etc.)
35      */
36     void activateTexture(GLuint textureUnit);
37 
38     /**
39      * Invalidate the cached value of the active texture unit.
40      */
41     void resetActiveTexture();
42 
43     /**
44      * Binds the specified texture as a GL_TEXTURE_2D texture.
45      * All texture bindings must be performed with this method or
46      * bindTexture(GLenum, GLuint).
47      */
48     void bindTexture(GLuint texture);
49 
50     /**
51      * Binds the specified texture with the specified render target.
52      * All texture bindings must be performed with this method or
53      * bindTexture(GLuint).
54      */
55     void bindTexture(GLenum target, GLuint texture);
56 
57     /**
58      * Deletes the specified texture and clears it from the cache
59      * of bound textures.
60      * All textures must be deleted using this method.
61      */
62     void deleteTexture(GLuint texture);
63 
64     /**
65      * Signals that the cache of bound textures should be cleared.
66      * Other users of the context may have altered which textures are bound.
67      */
68     void resetBoundTextures();
69 
70     /**
71      * Clear the cache of bound textures.
72      */
73     void unbindTexture(GLuint texture);
74 private:
75     // total number of texture units available for use
76     static const int kTextureUnitsCount = 4;
77 
78     TextureState();
79     GLuint mTextureUnit;
80 
81     // Caches texture bindings for the GL_TEXTURE_2D target
82     GLuint mBoundTextures[kTextureUnitsCount];
83 };
84 
85 } /* namespace uirenderer */
86 } /* namespace android */
87 
88 #endif // RENDERSTATE_BLEND_H
89