1 // 2 // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 // renderer11_utils.h: Conversion functions and other utility routines 8 // specific to the D3D11 renderer. 9 10 #ifndef LIBGLESV2_RENDERER_RENDERER11_UTILS_H 11 #define LIBGLESV2_RENDERER_RENDERER11_UTILS_H 12 13 #include "libGLESv2/angletypes.h" 14 15 namespace gl_d3d11 16 { 17 18 D3D11_BLEND ConvertBlendFunc(GLenum glBlend, bool isAlpha); 19 D3D11_BLEND_OP ConvertBlendOp(GLenum glBlendOp); 20 UINT8 ConvertColorMask(bool maskRed, bool maskGreen, bool maskBlue, bool maskAlpha); 21 22 D3D11_CULL_MODE ConvertCullMode(bool cullEnabled, GLenum cullMode); 23 24 D3D11_COMPARISON_FUNC ConvertComparison(GLenum comparison); 25 D3D11_DEPTH_WRITE_MASK ConvertDepthMask(bool depthWriteEnabled); 26 UINT8 ConvertStencilMask(GLuint stencilmask); 27 D3D11_STENCIL_OP ConvertStencilOp(GLenum stencilOp); 28 29 D3D11_FILTER ConvertFilter(GLenum minFilter, GLenum magFilter, float maxAnisotropy); 30 D3D11_TEXTURE_ADDRESS_MODE ConvertTextureWrap(GLenum wrap); 31 FLOAT ConvertMinLOD(GLenum minFilter, unsigned int lodOffset); 32 FLOAT ConvertMaxLOD(GLenum minFilter, unsigned int lodOffset); 33 34 DXGI_FORMAT ConvertRenderbufferFormat(GLenum format); 35 DXGI_FORMAT ConvertTextureFormat(GLenum format); 36 } 37 38 namespace d3d11_gl 39 { 40 41 GLenum ConvertBackBufferFormat(DXGI_FORMAT format); 42 GLenum ConvertDepthStencilFormat(DXGI_FORMAT format); 43 GLenum ConvertRenderbufferFormat(DXGI_FORMAT format); 44 GLenum ConvertTextureInternalFormat(DXGI_FORMAT format); 45 46 } 47 48 namespace d3d11 49 { 50 51 struct PositionTexCoordVertex 52 { 53 float x, y; 54 float u, v; 55 }; 56 void SetPositionTexCoordVertex(PositionTexCoordVertex* vertex, float x, float y, float u, float v); 57 58 struct PositionDepthColorVertex 59 { 60 float x, y, z; 61 float r, g, b, a; 62 }; 63 void SetPositionDepthColorVertex(PositionDepthColorVertex* vertex, float x, float y, float z, 64 const gl::Color &color); 65 66 size_t ComputePixelSizeBits(DXGI_FORMAT format); 67 size_t ComputeBlockSizeBits(DXGI_FORMAT format); 68 69 bool IsCompressed(DXGI_FORMAT format); 70 unsigned int GetTextureFormatDimensionAlignment(DXGI_FORMAT format); 71 72 bool IsDepthStencilFormat(DXGI_FORMAT format); 73 DXGI_FORMAT GetDepthTextureFormat(DXGI_FORMAT format); 74 DXGI_FORMAT GetDepthShaderResourceFormat(DXGI_FORMAT format); 75 76 HRESULT SetDebugName(ID3D11DeviceChild *resource, const char *name); 77 78 inline bool isDeviceLostError(HRESULT errorCode) 79 { 80 switch (errorCode) 81 { 82 case DXGI_ERROR_DEVICE_HUNG: 83 case DXGI_ERROR_DEVICE_REMOVED: 84 case DXGI_ERROR_DEVICE_RESET: 85 case DXGI_ERROR_DRIVER_INTERNAL_ERROR: 86 case DXGI_ERROR_NOT_CURRENTLY_AVAILABLE: 87 return true; 88 default: 89 return false; 90 } 91 } 92 93 } 94 95 #endif // LIBGLESV2_RENDERER_RENDERER11_UTILS_H 96