1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | // utilities.h: Conversion functions and other utility routines. |
16 | |
17 | #ifndef LIBGLESV2_UTILITIES_H |
18 | #define LIBGLESV2_UTILITIES_H |
19 | |
20 | #include "Device.hpp" |
21 | #include "common/Image.hpp" |
22 | #include "Texture.h" |
23 | |
24 | #include <GLES2/gl2.h> |
25 | #include <GLES2/gl2ext.h> |
26 | #include <GL/glcorearb.h> |
27 | #include <GL/glext.h> |
28 | |
29 | #include <string> |
30 | |
31 | namespace es2 |
32 | { |
33 | struct Color; |
34 | class Framebuffer; |
35 | |
36 | unsigned int UniformComponentCount(GLenum type); |
37 | GLenum UniformComponentType(GLenum type); |
38 | size_t UniformTypeSize(GLenum type); |
39 | bool IsSamplerUniform(GLenum type); |
40 | int VariableRowCount(GLenum type); |
41 | int VariableColumnCount(GLenum type); |
42 | int VariableRegisterCount(GLenum type); |
43 | int VariableRegisterSize(GLenum type); |
44 | |
45 | int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsigned int bitsSize); |
46 | |
47 | bool IsCompressed(GLint intenalformat); |
48 | bool IsSizedInternalFormat(GLint internalformat); // Not compressed. |
49 | GLenum ValidateSubImageParams(bool compressed, bool copy, GLenum target, GLint level, GLint xoffset, GLint yoffset, |
50 | GLsizei width, GLsizei height, GLenum format, GLenum type, Texture *texture); |
51 | GLenum ValidateSubImageParams(bool compressed, bool copy, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, |
52 | GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, Texture *texture); |
53 | bool ValidateCopyFormats(GLenum textureFormat, GLenum colorbufferFormat); |
54 | bool ValidateReadPixelsFormatType(const Framebuffer *framebuffer, GLenum format, GLenum type); |
55 | bool IsDepthTexture(GLint format); |
56 | bool IsStencilTexture(GLint format); |
57 | bool IsCubemapTextureTarget(GLenum target); |
58 | int CubeFaceIndex(GLenum cubeTarget); |
59 | bool IsTexImageTarget(GLenum target); |
60 | bool IsTextureTarget(GLenum target); |
61 | GLenum ValidateTextureFormatType(GLenum format, GLenum type, GLint internalformat, GLenum target); |
62 | size_t GetTypeSize(GLenum type); |
63 | sw::Format ConvertReadFormatType(GLenum format, GLenum type); |
64 | |
65 | bool IsColorRenderable(GLint internalformat); |
66 | bool IsDepthRenderable(GLint internalformat); |
67 | bool IsStencilRenderable(GLint internalformat); |
68 | bool IsMipmappable(GLint internalformat); |
69 | |
70 | GLuint GetAlphaSize(GLint internalformat); |
71 | GLuint GetRedSize(GLint internalformat); |
72 | GLuint GetGreenSize(GLint internalformat); |
73 | GLuint GetBlueSize(GLint internalformat); |
74 | GLuint GetDepthSize(GLint internalformat); |
75 | GLuint GetStencilSize(GLint internalformat); |
76 | |
77 | GLenum GetColorComponentType(GLint internalformat); |
78 | GLenum GetComponentType(GLint internalformat, GLenum attachment); |
79 | bool IsNormalizedInteger(GLint internalformat); |
80 | bool IsNonNormalizedInteger(GLint internalformat); |
81 | bool IsFloatFormat(GLint internalformat); |
82 | bool IsSignedNonNormalizedInteger(GLint internalformat); |
83 | bool IsUnsignedNonNormalizedInteger(GLint internalformat); |
84 | GLenum GetColorEncoding(GLint internalformat); |
85 | |
86 | // Parse the base uniform name and array index. Returns the base name of the uniform. outSubscript is |
87 | // set to GL_INVALID_INDEX if the provided name is not an array or the array index is invalid. |
88 | std::string ParseUniformName(const std::string &name, unsigned int *outSubscript); |
89 | |
90 | bool FloatFitsInInt(float f); |
91 | } |
92 | |
93 | namespace es2sw |
94 | { |
95 | sw::DepthCompareMode ConvertDepthComparison(GLenum comparison); |
96 | sw::StencilCompareMode ConvertStencilComparison(GLenum comparison); |
97 | sw::Color<float> ConvertColor(es2::Color color); |
98 | sw::BlendFactor ConvertBlendFunc(GLenum blend); |
99 | sw::BlendOperation ConvertBlendOp(GLenum blendOp); |
100 | sw::LogicalOperation ConvertLogicalOperation(GLenum logicalOperation); |
101 | sw::StencilOperation ConvertStencilOp(GLenum stencilOp); |
102 | sw::AddressingMode ConvertTextureWrap(GLenum wrap); |
103 | sw::CompareFunc ConvertCompareFunc(GLenum compareFunc, GLenum compareMode); |
104 | sw::SwizzleType ConvertSwizzleType(GLenum swizzleType); |
105 | sw::CullMode ConvertCullMode(GLenum cullFace, GLenum frontFace); |
106 | unsigned int ConvertColorMask(bool red, bool green, bool blue, bool alpha); |
107 | sw::MipmapType ConvertMipMapFilter(GLenum minFilter); |
108 | sw::FilterType ConvertTextureFilter(GLenum minFilter, GLenum magFilter, float maxAnisotropy); |
109 | bool ConvertPrimitiveType(GLenum primitiveType, GLsizei elementCount, GLenum elementType, sw::DrawType &swPrimitiveType, int &primitiveCount, int &verticesPerPrimitive); |
110 | } |
111 | |
112 | namespace sw2es |
113 | { |
114 | GLenum ConvertBackBufferFormat(sw::Format format); |
115 | GLenum ConvertDepthStencilFormat(sw::Format format); |
116 | } |
117 | |
118 | #endif // LIBGLESV2_UTILITIES_H |
119 | |