Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 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 | |
Chris Craik | 68f5b8a | 2015-09-09 13:23:09 -0700 | [diff] [blame] | 26 | class SkBitmap; |
| 27 | |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 28 | namespace android { |
| 29 | namespace uirenderer { |
| 30 | |
Chris Craik | 68f5b8a | 2015-09-09 13:23:09 -0700 | [diff] [blame] | 31 | class Texture; |
| 32 | |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 33 | class TextureState { |
| 34 | friend class Caches; // TODO: move to RenderState |
| 35 | public: |
| 36 | /** |
| 37 | * Activate the specified texture unit. The texture unit must |
| 38 | * be specified using an integer number (0 for GL_TEXTURE0 etc.) |
| 39 | */ |
| 40 | void activateTexture(GLuint textureUnit); |
| 41 | |
| 42 | /** |
| 43 | * Invalidate the cached value of the active texture unit. |
| 44 | */ |
| 45 | void resetActiveTexture(); |
| 46 | |
| 47 | /** |
| 48 | * Binds the specified texture as a GL_TEXTURE_2D texture. |
| 49 | * All texture bindings must be performed with this method or |
| 50 | * bindTexture(GLenum, GLuint). |
| 51 | */ |
| 52 | void bindTexture(GLuint texture); |
| 53 | |
| 54 | /** |
| 55 | * Binds the specified texture with the specified render target. |
| 56 | * All texture bindings must be performed with this method or |
| 57 | * bindTexture(GLuint). |
| 58 | */ |
| 59 | void bindTexture(GLenum target, GLuint texture); |
| 60 | |
| 61 | /** |
| 62 | * Deletes the specified texture and clears it from the cache |
| 63 | * of bound textures. |
| 64 | * All textures must be deleted using this method. |
| 65 | */ |
| 66 | void deleteTexture(GLuint texture); |
| 67 | |
| 68 | /** |
| 69 | * Signals that the cache of bound textures should be cleared. |
| 70 | * Other users of the context may have altered which textures are bound. |
| 71 | */ |
| 72 | void resetBoundTextures(); |
| 73 | |
| 74 | /** |
| 75 | * Clear the cache of bound textures. |
| 76 | */ |
| 77 | void unbindTexture(GLuint texture); |
Chris Craik | 68f5b8a | 2015-09-09 13:23:09 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * Generates the texture from a bitmap into the specified texture structure. |
| 81 | * |
| 82 | * @param regenerate If true, the bitmap data is reuploaded into the texture, but |
| 83 | * no new texture is generated. |
| 84 | */ |
| 85 | void generateTexture(const SkBitmap* bitmap, Texture* texture, bool regenerate); |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 86 | private: |
| 87 | // total number of texture units available for use |
Chris Craik | e310f83 | 2015-07-13 13:34:07 -0700 | [diff] [blame] | 88 | static const int kTextureUnitsCount = 4; |
Chris Craik | 44eb2c0 | 2015-01-29 09:45:09 -0800 | [diff] [blame] | 89 | |
| 90 | TextureState(); |
| 91 | GLuint mTextureUnit; |
| 92 | |
| 93 | // Caches texture bindings for the GL_TEXTURE_2D target |
| 94 | GLuint mBoundTextures[kTextureUnitsCount]; |
| 95 | }; |
| 96 | |
| 97 | } /* namespace uirenderer */ |
| 98 | } /* namespace android */ |
| 99 | |
| 100 | #endif // RENDERSTATE_BLEND_H |