OSDN Git Service

Pixel unpack buffer validation follow up
[android-x86/external-swiftshader.git] / src / OpenGL / libGLESv2 / utilities.h
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
27 #include <string>
28
29 namespace es2
30 {
31         struct Color;
32         class Framebuffer;
33
34         unsigned int UniformComponentCount(GLenum type);
35         GLenum UniformComponentType(GLenum type);
36         size_t UniformTypeSize(GLenum type);
37         bool IsSamplerUniform(GLenum type);
38         int VariableRowCount(GLenum type);
39         int VariableColumnCount(GLenum type);
40         int VariableRegisterCount(GLenum type);
41         int VariableRegisterSize(GLenum type);
42
43         int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsigned int bitsSize);
44
45         bool IsCompressed(GLenum format, GLint clientVersion);
46         GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type);
47         GLenum ValidateCompressedFormat(GLenum format, GLint clientVersion, bool expectCompressedFormats);
48         GLenum ValidateSubImageParams(bool compressed, GLsizei width, GLsizei height, GLint xoffset, GLint yoffset, GLenum target, GLint level, GLenum sizedInternalFormat, Texture *texture);
49         GLenum ValidateSubImageParams(bool compressed, GLsizei width, GLsizei height, GLsizei depth, GLint xoffset, GLint yoffset, GLint zoffset, GLenum target, GLint level, GLenum sizedInternalFormat, Texture *texture);
50         bool IsValidReadPixelsFormatType(const Framebuffer *framebuffer, GLenum format, GLenum type, GLint clientVersion);
51         bool IsDepthTexture(GLenum format);
52         bool IsStencilTexture(GLenum format);
53         bool IsCubemapTextureTarget(GLenum target);
54         int CubeFaceIndex(GLenum cubeTarget);
55         bool IsTextureTarget(GLenum target);
56         bool ValidateTextureFormatType(GLenum format, GLenum type, GLint internalformat, GLint clientVersion);
57         GLsizei GetTypeSize(GLenum type);
58
59         bool IsColorRenderable(GLenum internalformat, GLint clientVersion, bool isTexture);
60         bool IsDepthRenderable(GLenum internalformat, GLint clientVersion);
61         bool IsStencilRenderable(GLenum internalformat, GLint clientVersion);
62
63         // Parse the base uniform name and array index.  Returns the base name of the uniform. outSubscript is
64         // set to GL_INVALID_INDEX if the provided name is not an array or the array index is invalid.
65         std::string ParseUniformName(const std::string &name, unsigned int *outSubscript);
66 }
67
68 namespace es2sw
69 {
70         sw::DepthCompareMode ConvertDepthComparison(GLenum comparison);
71         sw::StencilCompareMode ConvertStencilComparison(GLenum comparison);
72         sw::Color<float> ConvertColor(es2::Color color);
73         sw::BlendFactor ConvertBlendFunc(GLenum blend);
74         sw::BlendOperation ConvertBlendOp(GLenum blendOp);
75         sw::LogicalOperation ConvertLogicalOperation(GLenum logicalOperation);
76         sw::StencilOperation ConvertStencilOp(GLenum stencilOp);
77         sw::AddressingMode ConvertTextureWrap(GLenum wrap);
78         sw::CompareFunc ConvertCompareFunc(GLenum compareFunc, GLenum compareMode);
79         sw::SwizzleType ConvertSwizzleType(GLenum swizzleType);
80         sw::CullMode ConvertCullMode(GLenum cullFace, GLenum frontFace);
81         unsigned int ConvertColorMask(bool red, bool green, bool blue, bool alpha);
82         sw::MipmapType ConvertMipMapFilter(GLenum minFilter);
83         sw::FilterType ConvertTextureFilter(GLenum minFilter, GLenum magFilter, float maxAnisotropy);
84         bool ConvertPrimitiveType(GLenum primitiveType, GLsizei elementCount,  GLenum elementType, sw::DrawType &swPrimitiveType, int &primitiveCount, int &verticesPerPrimitive);
85         sw::Format ConvertRenderbufferFormat(GLenum format);
86 }
87
88 namespace sw2es
89 {
90         GLuint GetAlphaSize(sw::Format colorFormat);
91         GLuint GetRedSize(sw::Format colorFormat);
92         GLuint GetGreenSize(sw::Format colorFormat);
93         GLuint GetBlueSize(sw::Format colorFormat);
94         GLuint GetDepthSize(sw::Format depthFormat);
95         GLuint GetStencilSize(sw::Format stencilFormat);
96         GLenum GetComponentType(sw::Format format, GLenum attachment);
97
98         GLenum ConvertBackBufferFormat(sw::Format format);
99         GLenum ConvertDepthStencilFormat(sw::Format format);
100 }
101
102 #endif  // LIBGLESV2_UTILITIES_H