Upstream version 7.35.139.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / src / libGLESv2 / renderer / Renderer.h
1 //
2 // Copyright (c) 2012-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 // 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 const int versionWindowsVista = MAKEWORD(0x00, 0x06);
23 const int versionWindows7 = MAKEWORD(0x01, 0x06);
24
25 // Return the version of the operating system in a format suitable for ordering
26 // comparison.
27 inline int getComparableOSVersion()
28 {
29     DWORD version = GetVersion();
30     int majorVersion = LOBYTE(LOWORD(version));
31     int minorVersion = HIBYTE(LOWORD(version));
32     return MAKEWORD(minorVersion, majorVersion);
33 }
34
35 namespace egl
36 {
37 class Display;
38 }
39
40 namespace gl
41 {
42 class InfoLog;
43 class ProgramBinary;
44 class VertexAttribute;
45 class Buffer;
46 class Texture;
47 class Framebuffer;
48 }
49
50 namespace rx
51 {
52 class TextureStorageInterface2D;
53 class TextureStorageInterfaceCube;
54 class VertexBuffer;
55 class IndexBuffer;
56 class QueryImpl;
57 class FenceImpl;
58 class BufferStorage;
59 class Blit;
60 struct TranslatedIndexData;
61 class ShaderExecutable;
62 class SwapChain;
63 class RenderTarget;
64 class Image;
65 class TextureStorage;
66
67 typedef void * ShaderBlob;
68 typedef void (*pCompileFunc)();
69
70 struct ConfigDesc
71 {
72     GLenum  renderTargetFormat;
73     GLenum  depthStencilFormat;
74     GLint   multiSample;
75     bool    fastConfig;
76 };
77
78 struct dx_VertexConstants
79 {
80     float depthRange[4];
81     float viewAdjust[4];
82 };
83
84 struct dx_PixelConstants
85 {
86     float depthRange[4];
87     float viewCoords[4];
88     float depthFront[4];
89 };
90
91 enum ShaderType
92 {
93     SHADER_VERTEX,
94     SHADER_PIXEL,
95     SHADER_GEOMETRY
96 };
97
98 enum D3DWorkaroundType
99 {
100     ANGLE_D3D_WORKAROUND_NONE,
101     ANGLE_D3D_WORKAROUND_SKIP_OPTIMIZATION,
102     ANGLE_D3D_WORKAROUND_MAX_OPTIMIZATION
103 };
104
105 class Renderer
106 {
107   public:
108     explicit Renderer(egl::Display *display);
109     virtual ~Renderer();
110
111     virtual EGLint initialize() = 0;
112     virtual bool resetDevice() = 0;
113
114     virtual int generateConfigs(ConfigDesc **configDescList) = 0;
115     virtual void deleteConfigs(ConfigDesc *configDescList) = 0;
116
117     virtual void sync(bool block) = 0;
118
119     virtual SwapChain *createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) = 0;
120
121     virtual void setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler) = 0;
122     virtual void setTexture(gl::SamplerType type, int index, gl::Texture *texture) = 0;
123
124     virtual void setRasterizerState(const gl::RasterizerState &rasterState) = 0;
125     virtual void setBlendState(gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::Color &blendColor,
126                                unsigned int sampleMask) = 0;
127     virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
128                                       int stencilBackRef, bool frontFaceCCW) = 0;
129
130     virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled) = 0;
131     virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
132                              bool ignoreViewport) = 0;
133
134     virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer) = 0;
135     virtual void applyShaders(gl::ProgramBinary *programBinary) = 0;
136     virtual void applyUniforms(gl::ProgramBinary *programBinary, gl::UniformArray *uniformArray) = 0;
137     virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 0;
138     virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances) = 0;
139     virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo) = 0;
140
141     virtual void drawArrays(GLenum mode, GLsizei count, GLsizei instances) = 0;
142     virtual void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances) = 0;
143
144     virtual void clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) = 0;
145
146     virtual void markAllStateDirty() = 0;
147
148     // lost device
149     virtual void notifyDeviceLost() = 0;
150     virtual bool isDeviceLost() = 0;
151     virtual bool testDeviceLost(bool notify) = 0;
152     virtual bool testDeviceResettable() = 0;
153
154     // Renderer capabilities
155     virtual DWORD getAdapterVendor() const = 0;
156     virtual std::string getRendererDescription() const = 0;
157     virtual GUID getAdapterIdentifier() const = 0;
158
159     virtual bool getBGRATextureSupport() const = 0;
160     virtual bool getDXT1TextureSupport() = 0;
161     virtual bool getDXT3TextureSupport() = 0;
162     virtual bool getDXT5TextureSupport() = 0;
163     virtual bool getEventQuerySupport() = 0;
164     virtual bool getFloat32TextureSupport(bool *filtering, bool *renderable) = 0;
165     virtual bool getFloat16TextureSupport(bool *filtering, bool *renderable) = 0;
166     virtual bool getLuminanceTextureSupport() = 0;
167     virtual bool getLuminanceAlphaTextureSupport() = 0;
168     bool getVertexTextureSupport() const { return getMaxVertexTextureImageUnits() > 0; }
169     virtual unsigned int getMaxVertexTextureImageUnits() const = 0;
170     virtual unsigned int getMaxCombinedTextureImageUnits() const = 0;
171     virtual unsigned int getReservedVertexUniformVectors() const = 0;
172     virtual unsigned int getReservedFragmentUniformVectors() const = 0;
173     virtual unsigned int getMaxVertexUniformVectors() const = 0;
174     virtual unsigned int getMaxFragmentUniformVectors() const = 0;
175     virtual unsigned int getMaxVaryingVectors() const = 0;
176     virtual bool getNonPower2TextureSupport() const = 0;
177     virtual bool getDepthTextureSupport() const = 0;
178     virtual bool getOcclusionQuerySupport() const = 0;
179     virtual bool getInstancingSupport() const = 0;
180     virtual bool getTextureFilterAnisotropySupport() const = 0;
181     virtual float getTextureMaxAnisotropy() const = 0;
182     virtual bool getShareHandleSupport() const = 0;
183     virtual bool getDerivativeInstructionSupport() const = 0;
184     virtual bool getPostSubBufferSupport() const = 0;
185
186     virtual int getMajorShaderModel() const = 0;
187     virtual float getMaxPointSize() const = 0;
188     virtual int getMaxViewportDimension() const = 0;
189     virtual int getMaxTextureWidth() const = 0;
190     virtual int getMaxTextureHeight() const = 0;
191     virtual bool get32BitIndexSupport() const = 0;
192     virtual int getMinSwapInterval() const = 0;
193     virtual int getMaxSwapInterval() const = 0;
194
195     virtual GLsizei getMaxSupportedSamples() const = 0;
196
197     virtual unsigned int getMaxRenderTargets() const = 0;
198
199     // Pixel operations
200     virtual bool copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source) = 0;
201     virtual bool copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source) = 0;
202
203     virtual bool copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
204                            GLint xoffset, GLint yoffset, TextureStorageInterface2D *storage, GLint level) = 0;
205     virtual bool copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
206                            GLint xoffset, GLint yoffset, TextureStorageInterfaceCube *storage, GLenum target, GLint level) = 0;
207
208     virtual bool blitRect(gl::Framebuffer *readTarget, const gl::Rectangle &readRect, gl::Framebuffer *drawTarget, const gl::Rectangle &drawRect,
209                           bool blitRenderTarget, bool blitDepthStencil) = 0;
210     virtual void readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type,
211                             GLsizei outputPitch, bool packReverseRowOrder, GLint packAlignment, void* pixels) = 0;
212
213     // RenderTarget creation
214     virtual RenderTarget *createRenderTarget(SwapChain *swapChain, bool depth) = 0;
215     virtual RenderTarget *createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth) = 0;
216
217     // Shader operations
218     virtual ShaderExecutable *loadExecutable(const void *function, size_t length, rx::ShaderType type) = 0;
219     virtual ShaderExecutable *compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, rx::ShaderType type, D3DWorkaroundType workaround) = 0;
220
221     // Image operations
222     virtual Image *createImage() = 0;
223     virtual void generateMipmap(Image *dest, Image *source) = 0;
224     virtual TextureStorage *createTextureStorage2D(SwapChain *swapChain) = 0;
225     virtual TextureStorage *createTextureStorage2D(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, GLsizei width, GLsizei height) = 0;
226     virtual TextureStorage *createTextureStorageCube(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, int size) = 0;
227
228     // Buffer creation
229     virtual VertexBuffer *createVertexBuffer() = 0;
230     virtual IndexBuffer *createIndexBuffer() = 0;
231     virtual BufferStorage *createBufferStorage() = 0;
232
233     // Query and Fence creation
234     virtual QueryImpl *createQuery(GLenum type) = 0;
235     virtual FenceImpl *createFence() = 0;
236
237     virtual bool getLUID(LUID *adapterLuid) const = 0;
238
239   protected:
240     bool initializeCompiler();
241     ShaderBlob *compileToBinary(gl::InfoLog &infoLog, const char *hlsl, const char *profile, UINT optimizationFlags, bool alternateFlags);
242
243     egl::Display *mDisplay;
244
245   private:
246     DISALLOW_COPY_AND_ASSIGN(Renderer);
247
248     HMODULE mD3dCompilerModule;
249     pCompileFunc mD3DCompileFunc;
250 };
251
252 }
253 #endif // LIBGLESV2_RENDERER_RENDERER_H_