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 #define ANGLE_COMPILE_OPTIMIZATION_LEVEL D3DCOMPILE_OPTIMIZATION_LEVEL3
20 const int versionWindowsVista = MAKEWORD(0x00, 0x06);
21 const int versionWindows7 = MAKEWORD(0x01, 0x06);
23 // Return the version of the operating system in a format suitable for ordering
25 inline int getComparableOSVersion()
27 DWORD version = GetVersion();
28 int majorVersion = LOBYTE(LOWORD(version));
29 int minorVersion = HIBYTE(LOWORD(version));
30 return MAKEWORD(minorVersion, majorVersion);
42 class VertexAttribute;
50 class TextureStorageInterface2D;
51 class TextureStorageInterfaceCube;
58 struct TranslatedIndexData;
59 class ShaderExecutable;
65 typedef void * ShaderBlob;
66 typedef void (*pCompileFunc)();
70 GLenum renderTargetFormat;
71 GLenum depthStencilFormat;
76 struct dx_VertexConstants
82 struct dx_PixelConstants
96 enum D3DWorkaroundType
98 ANGLE_D3D_WORKAROUND_NONE,
99 ANGLE_D3D_WORKAROUND_SM3_OPTIMIZER
105 explicit Renderer(egl::Display *display);
108 virtual EGLint initialize() = 0;
109 virtual bool resetDevice() = 0;
111 virtual int generateConfigs(ConfigDesc **configDescList) = 0;
112 virtual void deleteConfigs(ConfigDesc *configDescList) = 0;
114 virtual void sync(bool block) = 0;
116 virtual SwapChain *createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) = 0;
118 virtual void setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler) = 0;
119 virtual void setTexture(gl::SamplerType type, int index, gl::Texture *texture) = 0;
121 virtual void setRasterizerState(const gl::RasterizerState &rasterState) = 0;
122 virtual void setBlendState(gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::Color &blendColor,
123 unsigned int sampleMask) = 0;
124 virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
125 int stencilBackRef, bool frontFaceCCW) = 0;
127 virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled) = 0;
128 virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
129 bool ignoreViewport) = 0;
131 virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer) = 0;
132 virtual void applyShaders(gl::ProgramBinary *programBinary) = 0;
133 virtual void applyUniforms(gl::ProgramBinary *programBinary, gl::UniformArray *uniformArray) = 0;
134 virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 0;
135 virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances) = 0;
136 virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo) = 0;
138 virtual void drawArrays(GLenum mode, GLsizei count, GLsizei instances) = 0;
139 virtual void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances) = 0;
141 virtual void clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) = 0;
143 virtual void markAllStateDirty() = 0;
146 virtual void notifyDeviceLost() = 0;
147 virtual bool isDeviceLost() = 0;
148 virtual bool testDeviceLost(bool notify) = 0;
149 virtual bool testDeviceResettable() = 0;
151 // Renderer capabilities
152 virtual DWORD getAdapterVendor() const = 0;
153 virtual std::string getRendererDescription() const = 0;
154 virtual GUID getAdapterIdentifier() const = 0;
156 virtual bool getBGRATextureSupport() const = 0;
157 virtual bool getDXT1TextureSupport() = 0;
158 virtual bool getDXT3TextureSupport() = 0;
159 virtual bool getDXT5TextureSupport() = 0;
160 virtual bool getEventQuerySupport() = 0;
161 virtual bool getFloat32TextureSupport(bool *filtering, bool *renderable) = 0;
162 virtual bool getFloat16TextureSupport(bool *filtering, bool *renderable) = 0;
163 virtual bool getLuminanceTextureSupport() = 0;
164 virtual bool getLuminanceAlphaTextureSupport() = 0;
165 bool getVertexTextureSupport() const { return getMaxVertexTextureImageUnits() > 0; }
166 virtual unsigned int getMaxVertexTextureImageUnits() const = 0;
167 virtual unsigned int getMaxCombinedTextureImageUnits() const = 0;
168 virtual unsigned int getReservedVertexUniformVectors() const = 0;
169 virtual unsigned int getReservedFragmentUniformVectors() const = 0;
170 virtual unsigned int getMaxVertexUniformVectors() const = 0;
171 virtual unsigned int getMaxFragmentUniformVectors() const = 0;
172 virtual unsigned int getMaxVaryingVectors() const = 0;
173 virtual bool getNonPower2TextureSupport() const = 0;
174 virtual bool getDepthTextureSupport() const = 0;
175 virtual bool getOcclusionQuerySupport() const = 0;
176 virtual bool getInstancingSupport() const = 0;
177 virtual bool getTextureFilterAnisotropySupport() const = 0;
178 virtual float getTextureMaxAnisotropy() const = 0;
179 virtual bool getShareHandleSupport() const = 0;
180 virtual bool getDerivativeInstructionSupport() const = 0;
181 virtual bool getPostSubBufferSupport() const = 0;
183 virtual int getMajorShaderModel() const = 0;
184 virtual float getMaxPointSize() const = 0;
185 virtual int getMaxViewportDimension() const = 0;
186 virtual int getMaxTextureWidth() const = 0;
187 virtual int getMaxTextureHeight() const = 0;
188 virtual bool get32BitIndexSupport() const = 0;
189 virtual int getMinSwapInterval() const = 0;
190 virtual int getMaxSwapInterval() const = 0;
192 virtual GLsizei getMaxSupportedSamples() const = 0;
194 virtual unsigned int getMaxRenderTargets() const = 0;
197 virtual bool copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source) = 0;
198 virtual bool copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source) = 0;
200 virtual bool copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
201 GLint xoffset, GLint yoffset, TextureStorageInterface2D *storage, GLint level) = 0;
202 virtual bool copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
203 GLint xoffset, GLint yoffset, TextureStorageInterfaceCube *storage, GLenum target, GLint level) = 0;
205 virtual bool blitRect(gl::Framebuffer *readTarget, const gl::Rectangle &readRect, gl::Framebuffer *drawTarget, const gl::Rectangle &drawRect,
206 bool blitRenderTarget, bool blitDepthStencil) = 0;
207 virtual void readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type,
208 GLsizei outputPitch, bool packReverseRowOrder, GLint packAlignment, void* pixels) = 0;
210 // RenderTarget creation
211 virtual RenderTarget *createRenderTarget(SwapChain *swapChain, bool depth) = 0;
212 virtual RenderTarget *createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth) = 0;
215 virtual ShaderExecutable *loadExecutable(const void *function, size_t length, rx::ShaderType type) = 0;
216 virtual ShaderExecutable *compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, rx::ShaderType type, D3DWorkaroundType workaround) = 0;
219 virtual Image *createImage() = 0;
220 virtual void generateMipmap(Image *dest, Image *source) = 0;
221 virtual TextureStorage *createTextureStorage2D(SwapChain *swapChain) = 0;
222 virtual TextureStorage *createTextureStorage2D(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, GLsizei width, GLsizei height) = 0;
223 virtual TextureStorage *createTextureStorageCube(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, int size) = 0;
226 virtual VertexBuffer *createVertexBuffer() = 0;
227 virtual IndexBuffer *createIndexBuffer() = 0;
228 virtual BufferStorage *createBufferStorage() = 0;
230 // Query and Fence creation
231 virtual QueryImpl *createQuery(GLenum type) = 0;
232 virtual FenceImpl *createFence() = 0;
234 virtual bool getLUID(LUID *adapterLuid) const = 0;
237 bool initializeCompiler();
238 ShaderBlob *compileToBinary(gl::InfoLog &infoLog, const char *hlsl, const char *profile, UINT optimizationFlags, bool alternateFlags);
240 egl::Display *mDisplay;
243 DISALLOW_COPY_AND_ASSIGN(Renderer);
245 HMODULE mD3dCompilerModule;
246 pCompileFunc mD3DCompileFunc;
250 #endif // LIBGLESV2_RENDERER_RENDERER_H_