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