1 /* 2 * Copyright (C) 2011 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 _TEXTURE_UTILS_H 17 #define _TEXTURE_UTILS_H 18 19 #include "GLEScontext.h" 20 #include "PaletteTexture.h" 21 #include "etc.h" 22 23 #include <functional> 24 #include <GLES/gl.h> 25 #include <GLES/glext.h> 26 27 typedef std::function<void(GLenum target, GLint level, 28 GLint internalformat, GLsizei width, GLsizei height, 29 GLint border, GLenum format, GLenum type, const GLvoid * data)> 30 glTexImage2D_t; 31 32 ETC2ImageFormat getEtcFormat(GLenum internalformat); 33 void getAstcFormats(const GLint** formats, size_t* formatsCount); 34 bool isAstcFormat(GLenum internalformat); 35 bool isEtcFormat(GLenum internalformat); 36 bool isEtc2Format(GLenum internalformat); 37 bool isBptcFormat(GLenum internalformat); 38 bool isS3tcFormat(GLenum internalformat); 39 bool isPaletteFormat(GLenum internalformat); 40 int getCompressedFormats(int majorVersion, int* formats); 41 void doCompressedTexImage2D(GLEScontext* ctx, GLenum target, GLint level, 42 GLenum internalformat, GLsizei width, 43 GLsizei height, GLint border, GLsizei imageSize, 44 const GLvoid* data, glTexImage2D_t glTexImage2DPtr); 45 void deleteRenderbufferGlobal(GLuint rbo); 46 GLenum decompressedInternalFormat(GLEScontext* ctx, GLenum compressedFormat); 47 48 bool isCubeMapFaceTarget(GLenum target); 49 bool isCoreProfileEmulatedFormat(GLenum format); 50 GLenum getCoreProfileEmulatedFormat(GLenum format); 51 GLint getCoreProfileEmulatedInternalFormat(GLint internalformat, GLenum type); 52 53 // TextureSwizzle: Structure to represent texture swizzling and help wth 54 // emulation of swizzle state. 55 // 56 // |to(Red|Green|Blue|Alpha)| represent the components 57 // (GL_(RED|GREEN|BLUE|ALPHA|ZERO|ONE)) that should be mapped 58 // from a source to destination image. 59 // 60 // For example, i.e., if |toRed| = GL_GREEN, the red component of the 61 // destination is read from the green component of the source. 62 // 63 // The functions below encode the swizzles to emulate deprecated formats 64 // such as GL_ALPHA/LUMINANCE plus utility functions to obtain the 65 // result of concatenating two swizzles in a row. 66 struct TextureSwizzle { 67 GLenum toRed = GL_RED; 68 GLenum toGreen = GL_GREEN; 69 GLenum toBlue = GL_BLUE; 70 GLenum toAlpha = GL_ALPHA; 71 }; 72 73 TextureSwizzle getSwizzleForEmulatedFormat(GLenum format); 74 TextureSwizzle getInverseSwizzleForEmulatedFormat(GLenum format); 75 76 GLenum swizzleComponentOf(const TextureSwizzle& s, GLenum component); 77 TextureSwizzle concatSwizzles(const TextureSwizzle& first, 78 const TextureSwizzle& next); 79 80 bool isSwizzleParam(GLenum pname); 81 82 bool isIntegerInternalFormat(GLint internalFormat); 83 84 void doCompressedTexImage2DNative(GLEScontext* ctx, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid* data); 85 void doCompressedTexSubImage2DNative(GLEScontext* ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid* data); 86 87 void forEachEtc2Format(std::function<void(GLint format)>); 88 void forEachAstcFormat(std::function<void(GLint format)>); 89 void forEachBptcFormat(std::function<void(GLint format)>); 90 void forEachS3tcForamt(std::function<void(GLint format)>); 91 92 bool isEtc2OrAstcFormat(GLenum format); 93 94 bool shouldPassthroughCompressedFormat(GLEScontext* ctx, GLenum internalformat); 95 96 uint32_t texImageSize(GLenum internalformat, 97 GLenum type, 98 int unpackAlignment, 99 GLsizei width, 100 GLsizei height); 101 102 #endif 103