1 //
2 // Copyright (c) 2002-2014 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 // renderer9_utils.h: Conversion functions and other utility routines
8 // specific to the D3D9 renderer
9 
10 #ifndef LIBANGLE_RENDERER_D3D_D3D9_RENDERER9UTILS_H_
11 #define LIBANGLE_RENDERER_D3D_D3D9_RENDERER9UTILS_H_
12 
13 #include "common/Color.h"
14 #include "libANGLE/Caps.h"
15 #include "libANGLE/Error.h"
16 
17 namespace gl
18 {
19 class FramebufferAttachment;
20 }
21 
22 namespace rx
23 {
24 class RenderTarget9;
25 struct WorkaroundsD3D;
26 
27 namespace gl_d3d9
28 {
29 
30 D3DCMPFUNC ConvertComparison(GLenum comparison);
31 D3DCOLOR ConvertColor(gl::ColorF color);
32 D3DBLEND ConvertBlendFunc(GLenum blend);
33 D3DBLENDOP ConvertBlendOp(GLenum blendOp);
34 D3DSTENCILOP ConvertStencilOp(GLenum stencilOp);
35 D3DTEXTUREADDRESS ConvertTextureWrap(GLenum wrap);
36 D3DCULL ConvertCullMode(GLenum cullFace, GLenum frontFace);
37 D3DCUBEMAP_FACES ConvertCubeFace(GLenum cubeFace);
38 DWORD ConvertColorMask(bool red, bool green, bool blue, bool alpha);
39 D3DTEXTUREFILTERTYPE ConvertMagFilter(GLenum magFilter, float maxAnisotropy);
40 void ConvertMinFilter(GLenum minFilter, D3DTEXTUREFILTERTYPE *d3dMinFilter, D3DTEXTUREFILTERTYPE *d3dMipFilter,
41                       float *d3dLodBias, float maxAnisotropy, size_t baseLevel);
42 D3DQUERYTYPE ConvertQueryType(GLenum queryType);
43 
44 D3DMULTISAMPLE_TYPE GetMultisampleType(GLuint samples);
45 
46 }
47 
48 namespace d3d9_gl
49 {
50 
51 unsigned int GetReservedVertexUniformVectors();
52 
53 unsigned int GetReservedFragmentUniformVectors();
54 
55 GLsizei GetSamplesCount(D3DMULTISAMPLE_TYPE type);
56 
57 bool IsFormatChannelEquivalent(D3DFORMAT d3dformat, GLenum format);
58 
59 void GenerateCaps(IDirect3D9 *d3d9,
60                   IDirect3DDevice9 *device,
61                   D3DDEVTYPE deviceType,
62                   UINT adapter,
63                   gl::Caps *caps,
64                   gl::TextureCapsMap *textureCapsMap,
65                   gl::Extensions *extensions,
66                   gl::Limitations *limitations);
67 }
68 
69 namespace d3d9
70 {
71 
72 GLuint ComputeBlockSize(D3DFORMAT format, GLuint width, GLuint height);
73 
74 void MakeValidSize(bool isImage, D3DFORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset);
75 
isDeviceLostError(HRESULT errorCode)76 inline bool isDeviceLostError(HRESULT errorCode)
77 {
78     switch (errorCode)
79     {
80       case D3DERR_DRIVERINTERNALERROR:
81       case D3DERR_DEVICELOST:
82       case D3DERR_DEVICEHUNG:
83       case D3DERR_DEVICEREMOVED:
84         return true;
85       default:
86         return false;
87     }
88 }
89 
90 WorkaroundsD3D GenerateWorkarounds();
91 }
92 
93 }
94 
95 #endif // LIBANGLE_RENDERER_D3D_D3D9_RENDERER9UTILS_H_
96