144eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik/*
244eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik * Copyright (C) 2015 The Android Open Source Project
344eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik *
444eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik * Licensed under the Apache License, Version 2.0 (the "License");
544eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik * you may not use this file except in compliance with the License.
644eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik * You may obtain a copy of the License at
744eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik *
844eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik *      http://www.apache.org/licenses/LICENSE-2.0
944eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik *
1044eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik * Unless required by applicable law or agreed to in writing, software
1144eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik * distributed under the License is distributed on an "AS IS" BASIS,
1244eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1344eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik * See the License for the specific language governing permissions and
1444eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik * limitations under the License.
1544eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik */
1644eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik#ifndef RENDERSTATE_TEXTURESTATE_H
1744eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik#define RENDERSTATE_TEXTURESTATE_H
1844eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik
1944eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik#include "Vertex.h"
2044eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik
2144eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik#include <GLES2/gl2.h>
2244eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik#include <GLES2/gl2ext.h>
2344eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik#include <SkXfermode.h>
2444eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik#include <memory>
2544eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik
2644eb2c00861098dd3e2950d923646814b4cc57c2Chris Craiknamespace android {
2744eb2c00861098dd3e2950d923646814b4cc57c2Chris Craiknamespace uirenderer {
2844eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik
2944eb2c00861098dd3e2950d923646814b4cc57c2Chris Craikclass TextureState {
3044eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    friend class Caches; // TODO: move to RenderState
3144eb2c00861098dd3e2950d923646814b4cc57c2Chris Craikpublic:
3244eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    /**
3344eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     * Activate the specified texture unit. The texture unit must
3444eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     * be specified using an integer number (0 for GL_TEXTURE0 etc.)
3544eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     */
3644eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    void activateTexture(GLuint textureUnit);
3744eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik
3844eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    /**
3944eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     * Invalidate the cached value of the active texture unit.
4044eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     */
4144eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    void resetActiveTexture();
4244eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik
4344eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    /**
4444eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     * Binds the specified texture as a GL_TEXTURE_2D texture.
4544eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     * All texture bindings must be performed with this method or
4644eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     * bindTexture(GLenum, GLuint).
4744eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     */
4844eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    void bindTexture(GLuint texture);
4944eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik
5044eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    /**
5144eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     * Binds the specified texture with the specified render target.
5244eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     * All texture bindings must be performed with this method or
5344eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     * bindTexture(GLuint).
5444eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     */
5544eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    void bindTexture(GLenum target, GLuint texture);
5644eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik
5744eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    /**
5844eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     * Deletes the specified texture and clears it from the cache
5944eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     * of bound textures.
6044eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     * All textures must be deleted using this method.
6144eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     */
6244eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    void deleteTexture(GLuint texture);
6344eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik
6444eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    /**
6544eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     * Signals that the cache of bound textures should be cleared.
6644eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     * Other users of the context may have altered which textures are bound.
6744eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     */
6844eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    void resetBoundTextures();
6944eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik
7044eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    /**
7144eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     * Clear the cache of bound textures.
7244eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik     */
7344eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    void unbindTexture(GLuint texture);
7444eb2c00861098dd3e2950d923646814b4cc57c2Chris Craikprivate:
7544eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    // total number of texture units available for use
76e310f83d591dc3fb7bd5c684239481a586f00662Chris Craik    static const int kTextureUnitsCount = 4;
7744eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik
7844eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    TextureState();
7944eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    GLuint mTextureUnit;
8044eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik
8144eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    // Caches texture bindings for the GL_TEXTURE_2D target
8244eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik    GLuint mBoundTextures[kTextureUnitsCount];
8344eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik};
8444eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik
8544eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik} /* namespace uirenderer */
8644eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik} /* namespace android */
8744eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik
8844eb2c00861098dd3e2950d923646814b4cc57c2Chris Craik#endif // RENDERSTATE_BLEND_H
89