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