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 enum D3DWorkaroundType 97 { 98 ANGLE_D3D_WORKAROUND_NONE, 99 ANGLE_D3D_WORKAROUND_SM3_OPTIMIZER 100 }; 101 102 class Renderer 103 { 104 public: 105 explicit Renderer(egl::Display *display); 106 virtual ~Renderer(); 107 108 virtual EGLint initialize() = 0; 109 virtual bool resetDevice() = 0; 110 111 virtual int generateConfigs(ConfigDesc **configDescList) = 0; 112 virtual void deleteConfigs(ConfigDesc *configDescList) = 0; 113 114 virtual void sync(bool block) = 0; 115 116 virtual SwapChain *createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) = 0; 117 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; 120 121 virtual void setRasterizerState(const gl::RasterizerState &rasterState) = 0; 122 virtual void setBlendState(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; 126 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; 130 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; 137 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; 140 141 virtual void clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) = 0; 142 143 virtual void markAllStateDirty() = 0; 144 145 // lost device 146 virtual void notifyDeviceLost() = 0; 147 virtual bool isDeviceLost() = 0; 148 virtual bool testDeviceLost(bool notify) = 0; 149 virtual bool testDeviceResettable() = 0; 150 151 // Renderer capabilities 152 virtual DWORD getAdapterVendor() const = 0; 153 virtual std::string getRendererDescription() const = 0; 154 virtual GUID getAdapterIdentifier() const = 0; 155 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; 182 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; 191 192 virtual GLsizei getMaxSupportedSamples() const = 0; 193 194 virtual unsigned int getMaxRenderTargets() const = 0; 195 196 // Pixel operations 197 virtual bool copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source) = 0; 198 virtual bool copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source) = 0; 199 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; 204 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; 209 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; 213 214 // Shader operations 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; 217 218 // Image operations 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; 224 225 // Buffer creation 226 virtual VertexBuffer *createVertexBuffer() = 0; 227 virtual IndexBuffer *createIndexBuffer() = 0; 228 virtual BufferStorage *createBufferStorage() = 0; 229 230 // Query and Fence creation 231 virtual QueryImpl *createQuery(GLenum type) = 0; 232 virtual FenceImpl *createFence() = 0; 233 234 virtual bool getLUID(LUID *adapterLuid) const = 0; 235 236 protected: 237 bool initializeCompiler(); 238 ShaderBlob *compileToBinary(gl::InfoLog &infoLog, const char *hlsl, const char *profile, UINT optimizationFlags, bool alternateFlags); 239 240 egl::Display *mDisplay; 241 242 private: 243 DISALLOW_COPY_AND_ASSIGN(Renderer); 244 245 HMODULE mD3dCompilerModule; 246 pCompileFunc mD3DCompileFunc; 247 }; 248 249 } 250 #endif // LIBGLESV2_RENDERER_RENDERER_H_ 251