• 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 #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 IsTextureTarget(GLenum target);
60 	GLenum ValidateTextureFormatType(GLenum format, GLenum type, GLint internalformat, GLenum target);
61 	size_t GetTypeSize(GLenum type);
62 	sw::Format ConvertReadFormatType(GLenum format, GLenum type);
63 
64 	bool IsColorRenderable(GLint internalformat);
65 	bool IsDepthRenderable(GLint internalformat);
66 	bool IsStencilRenderable(GLint internalformat);
67 	bool IsMipmappable(GLint internalformat);
68 
69 	GLuint GetAlphaSize(GLint internalformat);
70 	GLuint GetRedSize(GLint internalformat);
71 	GLuint GetGreenSize(GLint internalformat);
72 	GLuint GetBlueSize(GLint internalformat);
73 	GLuint GetDepthSize(GLint internalformat);
74 	GLuint GetStencilSize(GLint internalformat);
75 
76 	GLenum GetColorComponentType(GLint internalformat);
77 	GLenum GetComponentType(GLint internalformat, GLenum attachment);
78 	bool IsNormalizedInteger(GLint internalformat);
79 	bool IsNonNormalizedInteger(GLint internalformat);
80 	bool IsFloatFormat(GLint internalformat);
81 	bool IsSignedNonNormalizedInteger(GLint internalformat);
82 	bool IsUnsignedNonNormalizedInteger(GLint internalformat);
83 	GLenum GetColorEncoding(GLint internalformat);
84 
85 	// Parse the base uniform name and array index.  Returns the base name of the uniform. outSubscript is
86 	// set to GL_INVALID_INDEX if the provided name is not an array or the array index is invalid.
87 	std::string ParseUniformName(const std::string &name, unsigned int *outSubscript);
88 }
89 
90 namespace es2sw
91 {
92 	sw::DepthCompareMode ConvertDepthComparison(GLenum comparison);
93 	sw::StencilCompareMode ConvertStencilComparison(GLenum comparison);
94 	sw::Color<float> ConvertColor(es2::Color color);
95 	sw::BlendFactor ConvertBlendFunc(GLenum blend);
96 	sw::BlendOperation ConvertBlendOp(GLenum blendOp);
97 	sw::LogicalOperation ConvertLogicalOperation(GLenum logicalOperation);
98 	sw::StencilOperation ConvertStencilOp(GLenum stencilOp);
99 	sw::AddressingMode ConvertTextureWrap(GLenum wrap);
100 	sw::CompareFunc ConvertCompareFunc(GLenum compareFunc, GLenum compareMode);
101 	sw::SwizzleType ConvertSwizzleType(GLenum swizzleType);
102 	sw::CullMode ConvertCullMode(GLenum cullFace, GLenum frontFace);
103 	unsigned int ConvertColorMask(bool red, bool green, bool blue, bool alpha);
104 	sw::MipmapType ConvertMipMapFilter(GLenum minFilter);
105 	sw::FilterType ConvertTextureFilter(GLenum minFilter, GLenum magFilter, float maxAnisotropy);
106 	bool ConvertPrimitiveType(GLenum primitiveType, GLsizei elementCount,  GLenum elementType, sw::DrawType &swPrimitiveType, int &primitiveCount, int &verticesPerPrimitive);
107 }
108 
109 namespace sw2es
110 {
111 	GLenum ConvertBackBufferFormat(sw::Format format);
112 	GLenum ConvertDepthStencilFormat(sw::Format format);
113 }
114 
115 #endif  // LIBGLESV2_UTILITIES_H
116