daniel@transgaming.com | feae9b3 | 2012-11-28 19:34:56 +0000 | [diff] [blame] | 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 | |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 10 | #define GL_APICALL |
| 11 | #include <GLES2/gl2.h> |
| 12 | #include <GLES2/gl2ext.h> |
daniel@transgaming.com | feae9b3 | 2012-11-28 19:34:56 +0000 | [diff] [blame] | 13 | #include <d3d11.h> |
| 14 | |
daniel@transgaming.com | fa34b34 | 2012-11-28 19:38:01 +0000 | [diff] [blame] | 15 | #include "libGLESv2/angletypes.h" |
| 16 | |
| 17 | namespace gl_d3d11 |
| 18 | { |
| 19 | |
daniel@transgaming.com | 90c634a | 2013-01-11 04:10:01 +0000 | [diff] [blame] | 20 | D3D11_BLEND ConvertBlendFunc(GLenum glBlend, bool isAlpha); |
daniel@transgaming.com | fa34b34 | 2012-11-28 19:38:01 +0000 | [diff] [blame] | 21 | D3D11_BLEND_OP ConvertBlendOp(GLenum glBlendOp); |
| 22 | UINT8 ConvertColorMask(bool maskRed, bool maskGreen, bool maskBlue, bool maskAlpha); |
| 23 | |
| 24 | D3D11_CULL_MODE ConvertCullMode(bool cullEnabled, GLenum cullMode); |
| 25 | |
daniel@transgaming.com | c820c12 | 2012-11-28 19:38:30 +0000 | [diff] [blame] | 26 | D3D11_COMPARISON_FUNC ConvertComparison(GLenum comparison); |
| 27 | D3D11_DEPTH_WRITE_MASK ConvertDepthMask(bool depthWriteEnabled); |
| 28 | UINT8 ConvertStencilMask(GLuint stencilmask); |
| 29 | D3D11_STENCIL_OP ConvertStencilOp(GLenum stencilOp); |
| 30 | |
daniel@transgaming.com | 3d34a8a | 2013-01-11 04:07:48 +0000 | [diff] [blame] | 31 | D3D11_FILTER ConvertFilter(GLenum minFilter, GLenum magFilter, float maxAnisotropy); |
| 32 | D3D11_TEXTURE_ADDRESS_MODE ConvertTextureWrap(GLenum wrap); |
| 33 | FLOAT ConvertMinLOD(GLenum minFilter); |
| 34 | FLOAT ConvertMaxLOD(GLenum minFilter); |
| 35 | |
daniel@transgaming.com | 8fb65c8 | 2012-12-20 21:07:49 +0000 | [diff] [blame] | 36 | DXGI_FORMAT ConvertRenderbufferFormat(GLenum format); |
daniel@transgaming.com | a8aac67 | 2012-12-20 21:08:00 +0000 | [diff] [blame] | 37 | DXGI_FORMAT ConvertTextureFormat(GLenum format); |
daniel@transgaming.com | fa34b34 | 2012-11-28 19:38:01 +0000 | [diff] [blame] | 38 | } |
daniel@transgaming.com | 6b14771 | 2012-11-28 19:37:24 +0000 | [diff] [blame] | 39 | |
daniel@transgaming.com | feae9b3 | 2012-11-28 19:34:56 +0000 | [diff] [blame] | 40 | namespace d3d11_gl |
| 41 | { |
| 42 | |
| 43 | GLenum ConvertBackBufferFormat(DXGI_FORMAT format); |
| 44 | GLenum ConvertDepthStencilFormat(DXGI_FORMAT format); |
| 45 | GLenum ConvertRenderbufferFormat(DXGI_FORMAT format); |
| 46 | GLenum ConvertTextureInternalFormat(DXGI_FORMAT format); |
daniel@transgaming.com | 8fb65c8 | 2012-12-20 21:07:49 +0000 | [diff] [blame] | 47 | |
daniel@transgaming.com | feae9b3 | 2012-11-28 19:34:56 +0000 | [diff] [blame] | 48 | } |
| 49 | |
daniel@transgaming.com | 8fb65c8 | 2012-12-20 21:07:49 +0000 | [diff] [blame] | 50 | namespace d3d11 |
daniel@transgaming.com | feae9b3 | 2012-11-28 19:34:56 +0000 | [diff] [blame] | 51 | { |
shannon.woods@transgaming.com | f3d8207 | 2013-01-25 21:50:43 +0000 | [diff] [blame] | 52 | |
| 53 | struct PositionTexCoordVertex |
| 54 | { |
| 55 | float x, y; |
| 56 | float u, v; |
| 57 | }; |
| 58 | void SetPositionTexCoordVertex(PositionTexCoordVertex* vertex, float x, float y, float u, float v); |
| 59 | |
shannon.woods@transgaming.com | 34f507c | 2013-01-25 21:52:15 +0000 | [diff] [blame] | 60 | struct PositionDepthColorVertex |
| 61 | { |
| 62 | float x, y, z; |
| 63 | float r, g, b, a; |
| 64 | }; |
| 65 | void SetPositionDepthColorVertex(PositionDepthColorVertex* vertex, float x, float y, float z, |
| 66 | const gl::Color &color); |
| 67 | |
daniel@transgaming.com | 8fb65c8 | 2012-12-20 21:07:49 +0000 | [diff] [blame] | 68 | size_t ComputePixelSizeBits(DXGI_FORMAT format); |
| 69 | size_t ComputeBlockSizeBits(DXGI_FORMAT format); |
daniel@transgaming.com | 00f2d9c | 2013-01-11 04:11:08 +0000 | [diff] [blame] | 70 | |
shannon.woods@transgaming.com | eec5c63 | 2013-02-28 23:04:21 +0000 | [diff] [blame^] | 71 | bool IsDepthStencilFormat(DXGI_FORMAT format); |
daniel@transgaming.com | 00f2d9c | 2013-01-11 04:11:08 +0000 | [diff] [blame] | 72 | HRESULT SetDebugName(ID3D11DeviceChild *resource, const char *name); |
daniel@transgaming.com | feae9b3 | 2012-11-28 19:34:56 +0000 | [diff] [blame] | 73 | } |
daniel@transgaming.com | a60160b | 2012-11-28 19:41:15 +0000 | [diff] [blame] | 74 | |
| 75 | inline bool isDeviceLostError(HRESULT errorCode) |
| 76 | { |
| 77 | switch (errorCode) |
| 78 | { |
| 79 | case DXGI_ERROR_DEVICE_HUNG: |
| 80 | case DXGI_ERROR_DEVICE_REMOVED: |
| 81 | case DXGI_ERROR_DEVICE_RESET: |
| 82 | case DXGI_ERROR_DRIVER_INTERNAL_ERROR: |
| 83 | case DXGI_ERROR_NOT_CURRENTLY_AVAILABLE: |
| 84 | return true; |
| 85 | default: |
| 86 | return false; |
| 87 | } |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 88 | } |