1//
2// Copyright (c) 2013 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// Blit11.cpp: Texture copy utility class.
8
9#ifndef LIBGLESV2_BLIT11_H_
10#define LIBGLESV2_BLIT11_H_
11
12#include "common/angleutils.h"
13#include "libGLESv2/angletypes.h"
14
15#include <map>
16
17namespace rx
18{
19class Renderer11;
20
21enum Filter
22{
23    Point,
24    Linear,
25};
26
27class Blit11
28{
29  public:
30    explicit Blit11(Renderer11 *renderer);
31    ~Blit11();
32
33    bool swizzleTexture(ID3D11ShaderResourceView *source, ID3D11RenderTargetView *dest, const gl::Extents &size,
34                        GLenum swizzleRed, GLenum swizzleGreen, GLenum swizzleBlue, GLenum swizzleAlpha);
35
36    bool copyTexture(ID3D11ShaderResourceView *source, const gl::Box &sourceArea, const gl::Extents &sourceSize,
37                     ID3D11RenderTargetView *dest, const gl::Box &destArea, const gl::Extents &destSize,
38                     const gl::Rectangle *scissor, GLenum destFormat, GLenum filter);
39
40    bool copyStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize,
41                     ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize,
42                     const gl::Rectangle *scissor);
43
44    bool copyDepth(ID3D11ShaderResourceView *source, const gl::Box &sourceArea, const gl::Extents &sourceSize,
45                   ID3D11DepthStencilView *dest, const gl::Box &destArea, const gl::Extents &destSize,
46                   const gl::Rectangle *scissor);
47
48    bool copyDepthStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize,
49                          ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize,
50                          const gl::Rectangle *scissor);
51
52  private:
53    rx::Renderer11 *mRenderer;
54
55    struct BlitParameters
56    {
57        GLenum mDestinationFormat;
58        bool mSignedInteger;
59        bool m3DBlit;
60    };
61
62    bool copyDepthStencil(ID3D11Resource *source, unsigned int sourceSubresource, const gl::Box &sourceArea, const gl::Extents &sourceSize,
63                          ID3D11Resource *dest, unsigned int destSubresource, const gl::Box &destArea, const gl::Extents &destSize,
64                          const gl::Rectangle *scissor, bool stencilOnly);
65
66    static bool compareBlitParameters(const BlitParameters &a, const BlitParameters &b);
67
68    typedef void (*WriteVertexFunction)(const gl::Box &sourceArea, const gl::Extents &sourceSize,
69                                        const gl::Box &destArea, const gl::Extents &destSize,
70                                        void *outVertices, unsigned int *outStride, unsigned int *outVertexCount,
71                                        D3D11_PRIMITIVE_TOPOLOGY *outTopology);
72
73    struct Shader
74    {
75        WriteVertexFunction mVertexWriteFunction;
76        ID3D11InputLayout *mInputLayout;
77        ID3D11VertexShader *mVertexShader;
78        ID3D11GeometryShader *mGeometryShader;
79        ID3D11PixelShader *mPixelShader;
80    };
81
82    typedef bool (*BlitParametersComparisonFunction)(const BlitParameters&, const BlitParameters &);
83    typedef std::map<BlitParameters, Shader, BlitParametersComparisonFunction> BlitShaderMap;
84    BlitShaderMap mBlitShaderMap;
85
86    void add2DBlitShaderToMap(GLenum destFormat, bool signedInteger, ID3D11PixelShader *ps);
87    void add3DBlitShaderToMap(GLenum destFormat, bool signedInteger, ID3D11PixelShader *ps);
88
89    struct SwizzleParameters
90    {
91        GLenum mDestinationType;
92        D3D11_SRV_DIMENSION mViewDimension;
93    };
94
95    static bool compareSwizzleParameters(const SwizzleParameters &a, const SwizzleParameters &b);
96
97    typedef bool (*SwizzleParametersComparisonFunction)(const SwizzleParameters&, const SwizzleParameters &);
98    typedef std::map<SwizzleParameters, Shader, SwizzleParametersComparisonFunction> SwizzleShaderMap;
99    SwizzleShaderMap mSwizzleShaderMap;
100
101    void addSwizzleShaderToMap(GLenum destType, D3D11_SRV_DIMENSION viewDimension, ID3D11PixelShader *ps);
102
103    void buildShaderMap();
104    void clearShaderMap();
105
106    ID3D11Buffer *mVertexBuffer;
107    ID3D11SamplerState *mPointSampler;
108    ID3D11SamplerState *mLinearSampler;
109    ID3D11RasterizerState *mScissorEnabledRasterizerState;
110    ID3D11RasterizerState *mScissorDisabledRasterizerState;
111    ID3D11DepthStencilState *mDepthStencilState;
112
113    ID3D11InputLayout *mQuad2DIL;
114    ID3D11VertexShader *mQuad2DVS;
115    ID3D11PixelShader *mDepthPS;
116
117    ID3D11InputLayout *mQuad3DIL;
118    ID3D11VertexShader *mQuad3DVS;
119    ID3D11GeometryShader *mQuad3DGS;
120
121    ID3D11Buffer *mSwizzleCB;
122
123    DISALLOW_COPY_AND_ASSIGN(Blit11);
124};
125
126}
127
128#endif   // LIBGLESV2_BLIT11_H_
129