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 // PixelTransfer11.h:
8 //   Buffer-to-Texture and Texture-to-Buffer data transfers.
9 //   Used to implement pixel unpack and pixel pack buffers in ES3.
10 
11 #ifndef LIBANGLE_RENDERER_D3D_D3D11_PIXELTRANSFER11_H_
12 #define LIBANGLE_RENDERER_D3D_D3D11_PIXELTRANSFER11_H_
13 
14 #include <GLES2/gl2.h>
15 
16 #include <map>
17 
18 #include "common/platform.h"
19 #include "libANGLE/Error.h"
20 #include "libANGLE/renderer/d3d/d3d11/ResourceManager11.h"
21 
22 namespace gl
23 {
24 
25 class Buffer;
26 struct Box;
27 struct Extents;
28 struct PixelUnpackState;
29 
30 }
31 
32 namespace rx
33 {
34 class Renderer11;
35 class RenderTargetD3D;
36 
37 class PixelTransfer11
38 {
39   public:
40     explicit PixelTransfer11(Renderer11 *renderer);
41     ~PixelTransfer11();
42 
43     // unpack: the source buffer is stored in the unpack state, and buffer strides
44     // offset: the start of the data within the unpack buffer
45     // destRenderTarget: individual slice/layer of a target texture
46     // destinationFormat/sourcePixelsType: determines shaders + shader parameters
47     // destArea: the sub-section of destRenderTarget to copy to
48     gl::Error copyBufferToTexture(const gl::Context *context,
49                                   const gl::PixelUnpackState &unpack,
50                                   unsigned int offset,
51                                   RenderTargetD3D *destRenderTarget,
52                                   GLenum destinationFormat,
53                                   GLenum sourcePixelsType,
54                                   const gl::Box &destArea);
55 
56   private:
57 
58     struct CopyShaderParams
59     {
60         unsigned int FirstPixelOffset;
61         unsigned int PixelsPerRow;
62         unsigned int RowStride;
63         unsigned int RowsPerSlice;
64         float PositionOffset[2];
65         float PositionScale[2];
66         int TexLocationOffset[2];
67         int TexLocationScale[2];
68         unsigned int FirstSlice;
69     };
70 
71     static void setBufferToTextureCopyParams(const gl::Box &destArea, const gl::Extents &destSize, GLenum internalFormat,
72                                              const gl::PixelUnpackState &unpack, unsigned int offset, CopyShaderParams *parametersOut);
73 
74     gl::Error loadResources();
75     gl::Error buildShaderMap();
76     const d3d11::PixelShader *findBufferToTexturePS(GLenum internalFormat) const;
77 
78     Renderer11 *mRenderer;
79 
80     bool mResourcesLoaded;
81     std::map<GLenum, d3d11::PixelShader> mBufferToTexturePSMap;
82     d3d11::VertexShader mBufferToTextureVS;
83     d3d11::GeometryShader mBufferToTextureGS;
84     d3d11::Buffer mParamsConstantBuffer;
85     CopyShaderParams mParamsData;
86 
87     d3d11::RasterizerState mCopyRasterizerState;
88     d3d11::DepthStencilState mCopyDepthStencilState;
89 };
90 
91 }  // namespace rx
92 
93 #endif // LIBANGLE_RENDERER_D3D_D3D11_PIXELTRANSFER11_H_
94