• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "gfxstream/etc.h"
22 #include "rgtc.h"
23 
24 #include <functional>
25 #include <GLES/gl.h>
26 #include <GLES/glext.h>
27 
28 typedef std::function<void(GLenum target, GLint level,
29     GLint internalformat, GLsizei width, GLsizei height,
30     GLint border, GLenum format, GLenum type, const GLvoid * data)>
31         glTexImage2D_t;
32 
33 ETC2ImageFormat getEtcFormat(GLenum internalformat);
34 void getAstcFormats(const GLint** formats, size_t* formatsCount);
35 bool isAstcFormat(GLenum internalformat);
36 bool isEtcFormat(GLenum internalformat);
37 bool isEtc2Format(GLenum internalformat);
38 bool isBptcFormat(GLenum internalformat);
39 bool isS3tcFormat(GLenum internalformat);
40 bool isPaletteFormat(GLenum internalformat);
41 bool isRgtcFormat(GLenum internalformat);
42 int getCompressedFormats(int majorVersion, int* formats);
43 void doCompressedTexImage2D(GLEScontext* ctx, GLenum target, GLint level,
44                             GLenum internalformat, GLsizei width,
45                             GLsizei height, GLint border, GLsizei imageSize,
46                             const GLvoid* data, glTexImage2D_t glTexImage2DPtr);
47 void deleteRenderbufferGlobal(GLuint rbo);
48 GLenum decompressedInternalFormat(GLEScontext* ctx, GLenum compressedFormat);
49 
50 bool isCubeMapFaceTarget(GLenum target);
51 bool isCoreProfileEmulatedFormat(GLenum format);
52 GLenum getCoreProfileEmulatedFormat(GLenum format);
53 GLint getCoreProfileEmulatedInternalFormat(GLint internalformat, GLenum type);
54 
55 // TextureSwizzle: Structure to represent texture swizzling and help wth
56 // emulation of swizzle state.
57 //
58 // |to(Red|Green|Blue|Alpha)| represent the components
59 // (GL_(RED|GREEN|BLUE|ALPHA|ZERO|ONE)) that should be mapped
60 // from a source to destination image.
61 //
62 // For example, i.e., if |toRed| = GL_GREEN, the red component of the
63 // destination is read from the green component of the source.
64 //
65 // The functions below encode the swizzles to emulate deprecated formats
66 // such as GL_ALPHA/LUMINANCE plus utility functions to obtain the
67 // result of concatenating two swizzles in a row.
68 struct TextureSwizzle {
69     GLenum toRed = GL_RED;
70     GLenum toGreen = GL_GREEN;
71     GLenum toBlue = GL_BLUE;
72     GLenum toAlpha = GL_ALPHA;
73 };
74 
75 TextureSwizzle getSwizzleForEmulatedFormat(GLenum format);
76 TextureSwizzle getInverseSwizzleForEmulatedFormat(GLenum format);
77 
78 GLenum swizzleComponentOf(const TextureSwizzle& s, GLenum component);
79 TextureSwizzle concatSwizzles(const TextureSwizzle& first,
80                               const TextureSwizzle& next);
81 
82 bool isSwizzleParam(GLenum pname);
83 
84 bool isIntegerInternalFormat(GLint internalFormat);
85 
86 void doCompressedTexImage2DNative(GLEScontext* ctx, GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid* data);
87 void doCompressedTexSubImage2DNative(GLEScontext* ctx, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLsizei imageSize, const GLvoid* data);
88 
89 void forEachEtc2Format(std::function<void(GLint format)>);
90 void forEachAstcFormat(std::function<void(GLint format)>);
91 void forEachBptcFormat(std::function<void(GLint format)>);
92 void forEachS3tcForamt(std::function<void(GLint format)>);
93 
94 bool isEtc2OrAstcFormat(GLenum format);
95 
96 bool shouldPassthroughCompressedFormat(GLEScontext* ctx, GLenum internalformat);
97 
98 uint32_t texImageSize(GLenum internalformat,
99                       GLenum type,
100                       int unpackAlignment,
101                       GLsizei width,
102                       GLsizei height);
103 
104 GLenum getFormatFromInternalFormat(GLint internalFormat);
105 GLenum getTypeFromInternalFormat(GLint internalFormat);
106 
107 class TextureUnpackReset {
108    public:
109     // Initial value for unpack
110     static constexpr GLint kUnpackRowLength = 0;
111     static constexpr GLint kUnpackImageHeight = 0;
112     static constexpr GLint kUnpackSkipRows = 0;
113     static constexpr GLint kUnpackSkipPixels = 0;
114     static constexpr GLint kUnpackSkipImages = 0;
115     static constexpr GLint kUnpackAlignment = 4;
116 
117     TextureUnpackReset(GLEScontext* ctx);
118     ~TextureUnpackReset();
119 
120     GLint unpackRowLength;
121     GLint unpackImageHeight;
122     GLint unpackSkipRows;
123     GLint unpackSkipPixels;
124     GLint unpackSkipImages;
125     GLint unpackAlignment;
126     GLEScontext* glesContext = nullptr;
127    private:
128     GLint unpackCheckAndUpdate(GLenum name, GLint newValue);
129 };
130 
131 #endif
132