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