Upstream version 8.37.180.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / src / libGLESv2 / renderer / Renderer.h
1 //
2 // Copyright (c) 2012-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 // Renderer.h: Defines a back-end specific class that hides the details of the
8 // implementation-specific renderer.
9
10 #ifndef LIBGLESV2_RENDERER_RENDERER_H_
11 #define LIBGLESV2_RENDERER_RENDERER_H_
12
13 #include "libGLESv2/Uniform.h"
14 #include "libGLESv2/angletypes.h"
15
16 #if !defined(ANGLE_COMPILE_OPTIMIZATION_LEVEL)
17 // WARNING: D3DCOMPILE_OPTIMIZATION_LEVEL3 may lead to a DX9 shader compiler hang.
18 // It should only be used selectively to work around specific bugs.
19 #define ANGLE_COMPILE_OPTIMIZATION_LEVEL D3DCOMPILE_OPTIMIZATION_LEVEL1
20 #endif
21
22 namespace egl
23 {
24 class Display;
25 }
26
27 namespace gl
28 {
29 class InfoLog;
30 class ProgramBinary;
31 struct LinkedVarying;
32 class VertexAttribute;
33 class Buffer;
34 class Texture;
35 class Framebuffer;
36 struct VertexAttribCurrentValueData;
37 }
38
39 namespace rx
40 {
41 class TextureStorageInterface2D;
42 class TextureStorageInterfaceCube;
43 class TextureStorageInterface3D;
44 class TextureStorageInterface2DArray;
45 class VertexBuffer;
46 class IndexBuffer;
47 class QueryImpl;
48 class FenceImpl;
49 class BufferStorage;
50 struct TranslatedIndexData;
51 class ShaderExecutable;
52 class SwapChain;
53 class RenderTarget;
54 class Image;
55 class TextureStorage;
56 class UniformStorage;
57
58 struct ConfigDesc
59 {
60     GLenum  renderTargetFormat;
61     GLenum  depthStencilFormat;
62     GLint   multiSample;
63     bool    fastConfig;
64     bool    es3Capable;
65 };
66
67 struct dx_VertexConstants
68 {
69     float depthRange[4];
70     float viewAdjust[4];
71 };
72
73 struct dx_PixelConstants
74 {
75     float depthRange[4];
76     float viewCoords[4];
77     float depthFront[4];
78 };
79
80 enum ShaderType
81 {
82     SHADER_VERTEX,
83     SHADER_PIXEL,
84     SHADER_GEOMETRY
85 };
86
87 class Renderer
88 {
89   public:
90     explicit Renderer(egl::Display *display);
91     virtual ~Renderer();
92
93     virtual EGLint initialize() = 0;
94     virtual bool resetDevice() = 0;
95
96     virtual int generateConfigs(ConfigDesc **configDescList) = 0;
97     virtual void deleteConfigs(ConfigDesc *configDescList) = 0;
98
99     virtual void sync(bool block) = 0;
100
101     virtual SwapChain *createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) = 0;
102
103     virtual void generateSwizzle(gl::Texture *texture) = 0;
104     virtual void setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler) = 0;
105     virtual void setTexture(gl::SamplerType type, int index, gl::Texture *texture) = 0;
106
107     virtual bool setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], const gl::Buffer *fragmentUniformBuffers[]) = 0;
108
109     virtual void setRasterizerState(const gl::RasterizerState &rasterState) = 0;
110     virtual void setBlendState(gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor,
111                                unsigned int sampleMask) = 0;
112     virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
113                                       int stencilBackRef, bool frontFaceCCW) = 0;
114
115     virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled) = 0;
116     virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
117                              bool ignoreViewport) = 0;
118
119     virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer) = 0;
120     virtual void applyShaders(gl::ProgramBinary *programBinary, bool rasterizerDiscard, bool transformFeedbackActive, const gl::VertexFormat inputLayout[]) = 0;
121     virtual void applyUniforms(const gl::ProgramBinary &programBinary) = 0;
122     virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 0;
123     virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], gl::VertexAttribCurrentValueData currentValues[],
124                                      GLint first, GLsizei count, GLsizei instances) = 0;
125     virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo) = 0;
126     virtual void applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuffers[], GLintptr offsets[]) = 0;
127
128     virtual void drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool transformFeedbackActive) = 0;
129     virtual void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices,
130                               gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances) = 0;
131
132     virtual void clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) = 0;
133
134     virtual void markAllStateDirty() = 0;
135
136     // lost device
137     virtual void notifyDeviceLost() = 0;
138     virtual bool isDeviceLost() = 0;
139     virtual bool testDeviceLost(bool notify) = 0;
140     virtual bool testDeviceResettable() = 0;
141
142     // Renderer capabilities
143     virtual DWORD getAdapterVendor() const = 0;
144     virtual std::string getRendererDescription() const = 0;
145     virtual GUID getAdapterIdentifier() const = 0;
146
147     virtual bool getBGRATextureSupport() const = 0;
148     virtual bool getDXT1TextureSupport() const = 0;
149     virtual bool getDXT3TextureSupport() const = 0;
150     virtual bool getDXT5TextureSupport() const = 0;
151     virtual bool getEventQuerySupport() const = 0;
152     virtual bool getFloat32TextureSupport() const = 0;
153     virtual bool getFloat32TextureFilteringSupport() const= 0;
154     virtual bool getFloat32TextureRenderingSupport() const= 0;
155     virtual bool getFloat16TextureSupport()  const= 0;
156     virtual bool getFloat16TextureFilteringSupport() const= 0;
157     virtual bool getFloat16TextureRenderingSupport() const = 0;
158     virtual bool getRGB565TextureSupport() const = 0;
159     virtual bool getLuminanceTextureSupport() const = 0;
160     virtual bool getLuminanceAlphaTextureSupport() const = 0;
161     virtual bool getRGTextureSupport() const = 0;
162     bool getVertexTextureSupport() const { return getMaxVertexTextureImageUnits() > 0; }
163     virtual unsigned int getMaxVertexTextureImageUnits() const = 0;
164     virtual unsigned int getMaxCombinedTextureImageUnits() const = 0;
165     virtual unsigned int getReservedVertexUniformVectors() const = 0;
166     virtual unsigned int getReservedFragmentUniformVectors() const = 0;
167     virtual unsigned int getMaxVertexUniformVectors() const = 0;
168     virtual unsigned int getMaxFragmentUniformVectors() const = 0;
169     virtual unsigned int getMaxVaryingVectors() const = 0;
170     virtual unsigned int getMaxVertexShaderUniformBuffers() const = 0;
171     virtual unsigned int getMaxFragmentShaderUniformBuffers() const = 0;
172     virtual unsigned int getReservedVertexUniformBuffers() const = 0;
173     virtual unsigned int getReservedFragmentUniformBuffers() const = 0;
174     virtual unsigned int getMaxTransformFeedbackBuffers() const = 0;
175     virtual unsigned int getMaxTransformFeedbackSeparateComponents() const = 0;
176     virtual unsigned int getMaxTransformFeedbackInterleavedComponents() const = 0;
177     virtual unsigned int getMaxUniformBufferSize() const = 0;
178     virtual bool getNonPower2TextureSupport() const = 0;
179     virtual bool getDepthTextureSupport() const = 0;
180     virtual bool getOcclusionQuerySupport() const = 0;
181     virtual bool getInstancingSupport() const = 0;
182     virtual bool getTextureFilterAnisotropySupport() const = 0;
183     virtual bool getPBOSupport() const = 0;
184     virtual float getTextureMaxAnisotropy() const = 0;
185     virtual bool getShareHandleSupport() const = 0;
186     virtual bool getDerivativeInstructionSupport() const = 0;
187     virtual bool getPostSubBufferSupport() const = 0;
188     virtual int getMaxRecommendedElementsIndices() const = 0;
189     virtual int getMaxRecommendedElementsVertices() const = 0;
190
191     virtual int getMajorShaderModel() const = 0;
192     virtual float getMaxPointSize() const = 0;
193     virtual int getMaxViewportDimension() const = 0;
194     virtual int getMaxTextureWidth() const = 0;
195     virtual int getMaxTextureHeight() const = 0;
196     virtual int getMaxTextureDepth() const = 0;
197     virtual int getMaxTextureArrayLayers() const = 0;
198     virtual bool get32BitIndexSupport() const = 0;
199     virtual int getMinSwapInterval() const = 0;
200     virtual int getMaxSwapInterval() const = 0;
201
202     virtual GLsizei getMaxSupportedSamples() const = 0;
203     virtual GLsizei getMaxSupportedFormatSamples(GLenum internalFormat) const = 0;
204     virtual GLsizei getNumSampleCounts(GLenum internalFormat) const = 0;
205     virtual void getSampleCounts(GLenum internalFormat, GLsizei bufSize, GLint *params) const = 0;
206
207     virtual unsigned int getMaxRenderTargets() const = 0;
208
209     // Pixel operations
210     virtual bool copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source) = 0;
211     virtual bool copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source) = 0;
212     virtual bool copyToRenderTarget(TextureStorageInterface3D *dest, TextureStorageInterface3D *source) = 0;
213     virtual bool copyToRenderTarget(TextureStorageInterface2DArray *dest, TextureStorageInterface2DArray *source) = 0;
214
215     virtual bool copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
216                            GLint xoffset, GLint yoffset, TextureStorageInterface2D *storage, GLint level) = 0;
217     virtual bool copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
218                            GLint xoffset, GLint yoffset, TextureStorageInterfaceCube *storage, GLenum target, GLint level) = 0;
219     virtual bool copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
220                            GLint xoffset, GLint yoffset, GLint zOffset, TextureStorageInterface3D *storage, GLint level) = 0;
221     virtual bool copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
222                            GLint xoffset, GLint yoffset, GLint zOffset, TextureStorageInterface2DArray *storage, GLint level) = 0;
223
224     virtual bool blitRect(gl::Framebuffer *readTarget, const gl::Rectangle &readRect, gl::Framebuffer *drawTarget, const gl::Rectangle &drawRect,
225                           const gl::Rectangle *scissor, bool blitRenderTarget, bool blitDepth, bool blitStencil, GLenum filter) = 0;
226     virtual void readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
227                             GLenum type, GLuint outputPitch, const gl::PixelPackState &pack, void* pixels) = 0;
228
229     // RenderTarget creation
230     virtual RenderTarget *createRenderTarget(SwapChain *swapChain, bool depth) = 0;
231     virtual RenderTarget *createRenderTarget(int width, int height, GLenum format, GLsizei samples) = 0;
232
233     // Shader operations
234     virtual ShaderExecutable *loadExecutable(const void *function, size_t length, rx::ShaderType type,
235                                              const std::vector<gl::LinkedVarying> &transformFeedbackVaryings,
236                                              bool separatedOutputBuffers) = 0;
237     virtual ShaderExecutable *compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, rx::ShaderType type,
238                                                   const std::vector<gl::LinkedVarying> &transformFeedbackVaryings,
239                                                   bool separatedOutputBuffers, D3DWorkaroundType workaround) = 0;
240     virtual UniformStorage *createUniformStorage(size_t storageSize) = 0;
241
242     // Image operations
243     virtual Image *createImage() = 0;
244     virtual void generateMipmap(Image *dest, Image *source) = 0;
245     virtual TextureStorage *createTextureStorage2D(SwapChain *swapChain) = 0;
246     virtual TextureStorage *createTextureStorage2D(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, int levels) = 0;
247     virtual TextureStorage *createTextureStorageCube(GLenum internalformat, bool renderTarget, int size, int levels) = 0;
248     virtual TextureStorage *createTextureStorage3D(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, GLsizei depth, int levels) = 0;
249     virtual TextureStorage *createTextureStorage2DArray(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, GLsizei depth, int levels) = 0;
250
251     // Buffer creation
252     virtual VertexBuffer *createVertexBuffer() = 0;
253     virtual IndexBuffer *createIndexBuffer() = 0;
254     virtual BufferStorage *createBufferStorage() = 0;
255
256     // Query and Fence creation
257     virtual QueryImpl *createQuery(GLenum type) = 0;
258     virtual FenceImpl *createFence() = 0;
259
260     // Current GLES client version
261     void setCurrentClientVersion(int clientVersion) { mCurrentClientVersion = clientVersion; }
262     int getCurrentClientVersion() const { return mCurrentClientVersion; }
263
264     // Buffer-to-texture and Texture-to-buffer copies
265     virtual bool supportsFastCopyBufferToTexture(GLenum internalFormat) const = 0;
266     virtual bool fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
267                                          GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea) = 0;
268
269     virtual bool getLUID(LUID *adapterLuid) const = 0;
270     virtual GLenum getNativeTextureFormat(GLenum internalFormat) const = 0;
271     virtual rx::VertexConversionType getVertexConversionType(const gl::VertexFormat &vertexFormat) const = 0;
272     virtual GLenum getVertexComponentType(const gl::VertexFormat &vertexFormat) const = 0;
273
274   protected:
275     egl::Display *mDisplay;
276
277   private:
278     DISALLOW_COPY_AND_ASSIGN(Renderer);
279
280     int mCurrentClientVersion;
281 };
282
283 }
284 #endif // LIBGLESV2_RENDERER_RENDERER_H_