Home | History | Annotate | Download | only in libGLESv2
      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 
     58 	bool IsColorRenderable(GLenum internalformat, GLint clientVersion, bool isTexture);
     59 	bool IsDepthRenderable(GLenum internalformat, GLint clientVersion);
     60 	bool IsStencilRenderable(GLenum internalformat, GLint clientVersion);
     61 
     62 	// Parse the base uniform name and array index.  Returns the base name of the uniform. outSubscript is
     63 	// set to GL_INVALID_INDEX if the provided name is not an array or the array index is invalid.
     64 	std::string ParseUniformName(const std::string &name, unsigned int *outSubscript);
     65 }
     66 
     67 namespace es2sw
     68 {
     69 	sw::DepthCompareMode ConvertDepthComparison(GLenum comparison);
     70 	sw::StencilCompareMode ConvertStencilComparison(GLenum comparison);
     71 	sw::Color<float> ConvertColor(es2::Color color);
     72 	sw::BlendFactor ConvertBlendFunc(GLenum blend);
     73 	sw::BlendOperation ConvertBlendOp(GLenum blendOp);
     74 	sw::LogicalOperation ConvertLogicalOperation(GLenum logicalOperation);
     75 	sw::StencilOperation ConvertStencilOp(GLenum stencilOp);
     76 	sw::AddressingMode ConvertTextureWrap(GLenum wrap);
     77 	sw::SwizzleType ConvertSwizzleType(GLenum swizzleType);
     78 	sw::CullMode ConvertCullMode(GLenum cullFace, GLenum frontFace);
     79 	unsigned int ConvertColorMask(bool red, bool green, bool blue, bool alpha);
     80 	sw::MipmapType ConvertMipMapFilter(GLenum minFilter);
     81 	sw::FilterType ConvertTextureFilter(GLenum minFilter, GLenum magFilter, float maxAnisotropy);
     82 	bool ConvertPrimitiveType(GLenum primitiveType, GLsizei elementCount,  GLenum elementType, sw::DrawType &swPrimitiveType, int &primitiveCount, int &verticesPerPrimitive);
     83 	sw::Format ConvertRenderbufferFormat(GLenum format);
     84 }
     85 
     86 namespace sw2es
     87 {
     88 	GLuint GetAlphaSize(sw::Format colorFormat);
     89 	GLuint GetRedSize(sw::Format colorFormat);
     90 	GLuint GetGreenSize(sw::Format colorFormat);
     91 	GLuint GetBlueSize(sw::Format colorFormat);
     92 	GLuint GetDepthSize(sw::Format depthFormat);
     93 	GLuint GetStencilSize(sw::Format stencilFormat);
     94 	GLenum GetComponentType(sw::Format format, GLenum attachment);
     95 
     96 	GLenum ConvertBackBufferFormat(sw::Format format);
     97 	GLenum ConvertDepthStencilFormat(sw::Format format);
     98 }
     99 
    100 #endif  // LIBGLESV2_UTILITIES_H
    101