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 LIBGL_UTILITIES_H 18 #define LIBGL_UTILITIES_H 19 20 #include "Device.hpp" 21 #include "Image.hpp" 22 #include "Texture.h" 23 24 #define _GDI32_ 25 #include <windows.h> 26 #include <GL/GL.h> 27 #include <GL/glext.h> 28 29 #include <string> 30 31 namespace gl 32 { 33 struct Color; 34 35 unsigned int UniformComponentCount(GLenum type); 36 GLenum UniformComponentType(GLenum type); 37 size_t UniformTypeSize(GLenum type); 38 int VariableRowCount(GLenum type); 39 int VariableColumnCount(GLenum type); 40 41 int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsigned int bitsSize); 42 43 int ComputePixelSize(GLenum format, GLenum type); 44 GLsizei ComputePitch(GLsizei width, GLenum format, GLenum type, GLint alignment); 45 GLsizei ComputeCompressedPitch(GLsizei width, GLenum format); 46 GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format); 47 bool IsCompressed(GLenum format); 48 bool IsDepthTexture(GLenum format); 49 bool IsStencilTexture(GLenum format); 50 bool IsCubemapTextureTarget(GLenum target); 51 int CubeFaceIndex(GLenum cubeTarget); 52 bool IsTextureTarget(GLenum target); 53 bool CheckTextureFormatType(GLenum format, GLenum type); 54 55 bool IsColorRenderable(GLenum internalformat); 56 bool IsDepthRenderable(GLenum internalformat); 57 bool IsStencilRenderable(GLenum internalformat); 58 } 59 60 namespace es2sw 61 { 62 sw::DepthCompareMode ConvertDepthComparison(GLenum comparison); 63 sw::StencilCompareMode ConvertStencilComparison(GLenum comparison); 64 sw::Color<float> ConvertColor(gl::Color color); 65 sw::BlendFactor ConvertBlendFunc(GLenum blend); 66 sw::BlendOperation ConvertBlendOp(GLenum blendOp); 67 sw::LogicalOperation ConvertLogicalOperation(GLenum logicalOperation); 68 sw::StencilOperation ConvertStencilOp(GLenum stencilOp); 69 sw::AddressingMode ConvertTextureWrap(GLenum wrap); 70 sw::CullMode ConvertCullMode(GLenum cullFace, GLenum frontFace); 71 unsigned int ConvertColorMask(bool red, bool green, bool blue, bool alpha); 72 sw::MipmapType ConvertMipMapFilter(GLenum minFilter); 73 sw::FilterType ConvertTextureFilter(GLenum minFilter, GLenum magFilter, float maxAnisotropy); 74 bool ConvertPrimitiveType(GLenum primitiveType, GLsizei elementCount, gl::PrimitiveType &swPrimitiveType, int &primitiveCount); 75 sw::Format ConvertRenderbufferFormat(GLenum format); 76 } 77 78 namespace sw2es 79 { 80 GLuint GetAlphaSize(sw::Format colorFormat); 81 GLuint GetRedSize(sw::Format colorFormat); 82 GLuint GetGreenSize(sw::Format colorFormat); 83 GLuint GetBlueSize(sw::Format colorFormat); 84 GLuint GetDepthSize(sw::Format depthFormat); 85 GLuint GetStencilSize(sw::Format stencilFormat); 86 87 GLenum ConvertBackBufferFormat(sw::Format format); 88 GLenum ConvertDepthStencilFormat(sw::Format format); 89 } 90 91 #endif // LIBGL_UTILITIES_H 92