• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(GLint intenalformat, GLint clientVersion);
46 	bool IsSizedInternalFormat(GLint internalformat);   // Not compressed.
47 	GLenum ValidateSubImageParams(bool compressed, bool copy, GLenum target, GLint level, GLint xoffset, GLint yoffset,
48 	                              GLsizei width, GLsizei height, GLenum format, GLenum type, Texture *texture, GLint clientVersion);
49 	GLenum ValidateSubImageParams(bool compressed, bool copy, GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
50 	                              GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, Texture *texture, GLint clientVersion);
51 	bool ValidateCopyFormats(GLenum textureFormat, GLenum colorbufferFormat);
52 	bool IsValidReadPixelsFormatType(const Framebuffer *framebuffer, GLenum format, GLenum type, GLint clientVersion);
53 	bool IsDepthTexture(GLenum format);
54 	bool IsStencilTexture(GLenum format);
55 	bool IsCubemapTextureTarget(GLenum target);
56 	int CubeFaceIndex(GLenum cubeTarget);
57 	bool IsTextureTarget(GLenum target);
58 	GLenum ValidateTextureFormatType(GLenum format, GLenum type, GLint internalformat, GLenum target, GLint clientVersion);
59 	size_t GetTypeSize(GLenum type);
60 
61 	bool IsColorRenderable(GLint internalformat, GLint clientVersion);
62 	bool IsDepthRenderable(GLint internalformat, GLint clientVersion);
63 	bool IsStencilRenderable(GLint internalformat, GLint clientVersion);
64 	bool IsMipmappable(GLint internalformat, GLint clientVersion);
65 
66 	GLuint GetAlphaSize(GLint internalformat);
67 	GLuint GetRedSize(GLint internalformat);
68 	GLuint GetGreenSize(GLint internalformat);
69 	GLuint GetBlueSize(GLint internalformat);
70 	GLuint GetDepthSize(GLint internalformat);
71 	GLuint GetStencilSize(GLint internalformat);
72 
73 	GLenum GetColorComponentType(GLint internalformat);
74 	GLenum GetComponentType(GLint internalformat, GLenum attachment);
75 	bool IsNormalizedInteger(GLint internalformat);
76 	bool IsNonNormalizedInteger(GLint internalformat);
77 	bool IsFloatFormat(GLint internalformat);
78 	bool IsSignedNonNormalizedInteger(GLint internalformat);
79 	bool IsUnsignedNonNormalizedInteger(GLint internalformat);
80 	GLenum GetColorEncoding(GLint internalformat);
81 
82 	// Parse the base uniform name and array index.  Returns the base name of the uniform. outSubscript is
83 	// set to GL_INVALID_INDEX if the provided name is not an array or the array index is invalid.
84 	std::string ParseUniformName(const std::string &name, unsigned int *outSubscript);
85 }
86 
87 namespace es2sw
88 {
89 	sw::DepthCompareMode ConvertDepthComparison(GLenum comparison);
90 	sw::StencilCompareMode ConvertStencilComparison(GLenum comparison);
91 	sw::Color<float> ConvertColor(es2::Color color);
92 	sw::BlendFactor ConvertBlendFunc(GLenum blend);
93 	sw::BlendOperation ConvertBlendOp(GLenum blendOp);
94 	sw::LogicalOperation ConvertLogicalOperation(GLenum logicalOperation);
95 	sw::StencilOperation ConvertStencilOp(GLenum stencilOp);
96 	sw::AddressingMode ConvertTextureWrap(GLenum wrap);
97 	sw::CompareFunc ConvertCompareFunc(GLenum compareFunc, GLenum compareMode);
98 	sw::SwizzleType ConvertSwizzleType(GLenum swizzleType);
99 	sw::CullMode ConvertCullMode(GLenum cullFace, GLenum frontFace);
100 	unsigned int ConvertColorMask(bool red, bool green, bool blue, bool alpha);
101 	sw::MipmapType ConvertMipMapFilter(GLenum minFilter);
102 	sw::FilterType ConvertTextureFilter(GLenum minFilter, GLenum magFilter, float maxAnisotropy);
103 	bool ConvertPrimitiveType(GLenum primitiveType, GLsizei elementCount,  GLenum elementType, sw::DrawType &swPrimitiveType, int &primitiveCount, int &verticesPerPrimitive);
104 }
105 
106 namespace sw2es
107 {
108 	GLenum ConvertBackBufferFormat(sw::Format format);
109 	GLenum ConvertDepthStencilFormat(sw::Format format);
110 }
111 
112 #endif  // LIBGLESV2_UTILITIES_H
113