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.
7 // Renderer.h: Defines a back-end specific class that hides the details of the
8 // implementation-specific renderer.
10 #ifndef LIBGLESV2_RENDERER_RENDERER_H_
11 #define LIBGLESV2_RENDERER_RENDERER_H_
13 #include "libGLESv2/Uniform.h"
14 #include "libGLESv2/angletypes.h"
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
22 const int versionWindowsVista = MAKEWORD(0x00, 0x06);
23 const int versionWindows7 = MAKEWORD(0x01, 0x06);
25 // Return the version of the operating system in a format suitable for ordering
27 inline int getComparableOSVersion()
29 DWORD version = GetVersion();
30 int majorVersion = LOBYTE(LOWORD(version));
31 int minorVersion = HIBYTE(LOWORD(version));
32 return MAKEWORD(minorVersion, majorVersion);
44 class VertexAttribute;
52 class TextureStorageInterface2D;
53 class TextureStorageInterfaceCube;
60 struct TranslatedIndexData;
61 class ShaderExecutable;
67 typedef void * ShaderBlob;
68 typedef void (*pCompileFunc)();
72 GLenum renderTargetFormat;
73 GLenum depthStencilFormat;
78 struct dx_VertexConstants
84 struct dx_PixelConstants
98 enum D3DWorkaroundType
100 ANGLE_D3D_WORKAROUND_NONE,
101 ANGLE_D3D_WORKAROUND_SKIP_OPTIMIZATION,
102 ANGLE_D3D_WORKAROUND_MAX_OPTIMIZATION
108 explicit Renderer(egl::Display *display);
111 virtual EGLint initialize() = 0;
112 virtual bool resetDevice() = 0;
114 virtual int generateConfigs(ConfigDesc **configDescList) = 0;
115 virtual void deleteConfigs(ConfigDesc *configDescList) = 0;
117 virtual void sync(bool block) = 0;
119 virtual SwapChain *createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) = 0;
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;
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;
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;
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;
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;
144 virtual void clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) = 0;
146 virtual void markAllStateDirty() = 0;
149 virtual void notifyDeviceLost() = 0;
150 virtual bool isDeviceLost() = 0;
151 virtual bool testDeviceLost(bool notify) = 0;
152 virtual bool testDeviceResettable() = 0;
154 // Renderer capabilities
155 virtual DWORD getAdapterVendor() const = 0;
156 virtual std::string getRendererDescription() const = 0;
157 virtual GUID getAdapterIdentifier() const = 0;
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;
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;
195 virtual GLsizei getMaxSupportedSamples() const = 0;
197 virtual unsigned int getMaxRenderTargets() const = 0;
200 virtual bool copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source) = 0;
201 virtual bool copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source) = 0;
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;
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;
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;
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;
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;
229 virtual VertexBuffer *createVertexBuffer() = 0;
230 virtual IndexBuffer *createIndexBuffer() = 0;
231 virtual BufferStorage *createBufferStorage() = 0;
233 // Query and Fence creation
234 virtual QueryImpl *createQuery(GLenum type) = 0;
235 virtual FenceImpl *createFence() = 0;
237 virtual bool getLUID(LUID *adapterLuid) const = 0;
240 bool initializeCompiler();
241 ShaderBlob *compileToBinary(gl::InfoLog &infoLog, const char *hlsl, const char *profile, UINT optimizationFlags, bool alternateFlags);
243 egl::Display *mDisplay;
246 DISALLOW_COPY_AND_ASSIGN(Renderer);
248 HMODULE mD3dCompilerModule;
249 pCompileFunc mD3DCompileFunc;
253 #endif // LIBGLESV2_RENDERER_RENDERER_H_