michael@0: // michael@0: // Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: // Renderer.h: Defines a back-end specific class that hides the details of the michael@0: // implementation-specific renderer. michael@0: michael@0: #ifndef LIBGLESV2_RENDERER_RENDERER_H_ michael@0: #define LIBGLESV2_RENDERER_RENDERER_H_ michael@0: michael@0: #include "libGLESv2/Uniform.h" michael@0: #include "libGLESv2/angletypes.h" michael@0: michael@0: #if !defined(ANGLE_COMPILE_OPTIMIZATION_LEVEL) michael@0: #define ANGLE_COMPILE_OPTIMIZATION_LEVEL D3DCOMPILE_OPTIMIZATION_LEVEL3 michael@0: #endif michael@0: michael@0: const int versionWindowsVista = MAKEWORD(0x00, 0x06); michael@0: const int versionWindows7 = MAKEWORD(0x01, 0x06); michael@0: michael@0: // Return the version of the operating system in a format suitable for ordering michael@0: // comparison. michael@0: inline int getComparableOSVersion() michael@0: { michael@0: DWORD version = GetVersion(); michael@0: int majorVersion = LOBYTE(LOWORD(version)); michael@0: int minorVersion = HIBYTE(LOWORD(version)); michael@0: return MAKEWORD(minorVersion, majorVersion); michael@0: } michael@0: michael@0: namespace egl michael@0: { michael@0: class Display; michael@0: } michael@0: michael@0: namespace gl michael@0: { michael@0: class InfoLog; michael@0: class ProgramBinary; michael@0: class VertexAttribute; michael@0: class Buffer; michael@0: class Texture; michael@0: class Framebuffer; michael@0: } michael@0: michael@0: namespace rx michael@0: { michael@0: class TextureStorageInterface2D; michael@0: class TextureStorageInterfaceCube; michael@0: class VertexBuffer; michael@0: class IndexBuffer; michael@0: class QueryImpl; michael@0: class FenceImpl; michael@0: class BufferStorage; michael@0: class Blit; michael@0: struct TranslatedIndexData; michael@0: class ShaderExecutable; michael@0: class SwapChain; michael@0: class RenderTarget; michael@0: class Image; michael@0: class TextureStorage; michael@0: michael@0: typedef void * ShaderBlob; michael@0: typedef void (*pCompileFunc)(); michael@0: michael@0: struct ConfigDesc michael@0: { michael@0: GLenum renderTargetFormat; michael@0: GLenum depthStencilFormat; michael@0: GLint multiSample; michael@0: bool fastConfig; michael@0: }; michael@0: michael@0: struct dx_VertexConstants michael@0: { michael@0: float depthRange[4]; michael@0: float viewAdjust[4]; michael@0: }; michael@0: michael@0: struct dx_PixelConstants michael@0: { michael@0: float depthRange[4]; michael@0: float viewCoords[4]; michael@0: float depthFront[4]; michael@0: }; michael@0: michael@0: enum ShaderType michael@0: { michael@0: SHADER_VERTEX, michael@0: SHADER_PIXEL, michael@0: SHADER_GEOMETRY michael@0: }; michael@0: michael@0: class Renderer michael@0: { michael@0: public: michael@0: explicit Renderer(egl::Display *display); michael@0: virtual ~Renderer(); michael@0: michael@0: virtual EGLint initialize() = 0; michael@0: virtual bool resetDevice() = 0; michael@0: michael@0: virtual int generateConfigs(ConfigDesc **configDescList) = 0; michael@0: virtual void deleteConfigs(ConfigDesc *configDescList) = 0; michael@0: michael@0: virtual void sync(bool block) = 0; michael@0: michael@0: virtual SwapChain *createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) = 0; michael@0: michael@0: virtual void setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler) = 0; michael@0: virtual void setTexture(gl::SamplerType type, int index, gl::Texture *texture) = 0; michael@0: michael@0: virtual void setRasterizerState(const gl::RasterizerState &rasterState) = 0; michael@0: virtual void setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor, michael@0: unsigned int sampleMask) = 0; michael@0: virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef, michael@0: int stencilBackRef, bool frontFaceCCW) = 0; michael@0: michael@0: virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled) = 0; michael@0: virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace, michael@0: bool ignoreViewport) = 0; michael@0: michael@0: virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer) = 0; michael@0: virtual void applyShaders(gl::ProgramBinary *programBinary) = 0; michael@0: virtual void applyUniforms(gl::ProgramBinary *programBinary, gl::UniformArray *uniformArray) = 0; michael@0: virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 0; michael@0: virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances) = 0; michael@0: virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo) = 0; michael@0: michael@0: virtual void drawArrays(GLenum mode, GLsizei count, GLsizei instances) = 0; michael@0: virtual void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances) = 0; michael@0: michael@0: virtual void clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) = 0; michael@0: michael@0: virtual void markAllStateDirty() = 0; michael@0: michael@0: // lost device michael@0: virtual void notifyDeviceLost() = 0; michael@0: virtual bool isDeviceLost() = 0; michael@0: virtual bool testDeviceLost(bool notify) = 0; michael@0: virtual bool testDeviceResettable() = 0; michael@0: michael@0: // Renderer capabilities michael@0: virtual DWORD getAdapterVendor() const = 0; michael@0: virtual std::string getRendererDescription() const = 0; michael@0: virtual GUID getAdapterIdentifier() const = 0; michael@0: michael@0: virtual bool getBGRATextureSupport() const = 0; michael@0: virtual bool getDXT1TextureSupport() = 0; michael@0: virtual bool getDXT3TextureSupport() = 0; michael@0: virtual bool getDXT5TextureSupport() = 0; michael@0: virtual bool getEventQuerySupport() = 0; michael@0: virtual bool getFloat32TextureSupport(bool *filtering, bool *renderable) = 0; michael@0: virtual bool getFloat16TextureSupport(bool *filtering, bool *renderable) = 0; michael@0: virtual bool getLuminanceTextureSupport() = 0; michael@0: virtual bool getLuminanceAlphaTextureSupport() = 0; michael@0: bool getVertexTextureSupport() const { return getMaxVertexTextureImageUnits() > 0; } michael@0: virtual unsigned int getMaxVertexTextureImageUnits() const = 0; michael@0: virtual unsigned int getMaxCombinedTextureImageUnits() const = 0; michael@0: virtual unsigned int getReservedVertexUniformVectors() const = 0; michael@0: virtual unsigned int getReservedFragmentUniformVectors() const = 0; michael@0: virtual unsigned int getMaxVertexUniformVectors() const = 0; michael@0: virtual unsigned int getMaxFragmentUniformVectors() const = 0; michael@0: virtual unsigned int getMaxVaryingVectors() const = 0; michael@0: virtual bool getNonPower2TextureSupport() const = 0; michael@0: virtual bool getDepthTextureSupport() const = 0; michael@0: virtual bool getOcclusionQuerySupport() const = 0; michael@0: virtual bool getInstancingSupport() const = 0; michael@0: virtual bool getTextureFilterAnisotropySupport() const = 0; michael@0: virtual float getTextureMaxAnisotropy() const = 0; michael@0: virtual bool getShareHandleSupport() const = 0; michael@0: virtual bool getDerivativeInstructionSupport() const = 0; michael@0: virtual bool getPostSubBufferSupport() const = 0; michael@0: michael@0: virtual int getMajorShaderModel() const = 0; michael@0: virtual float getMaxPointSize() const = 0; michael@0: virtual int getMaxViewportDimension() const = 0; michael@0: virtual int getMaxTextureWidth() const = 0; michael@0: virtual int getMaxTextureHeight() const = 0; michael@0: virtual bool get32BitIndexSupport() const = 0; michael@0: virtual int getMinSwapInterval() const = 0; michael@0: virtual int getMaxSwapInterval() const = 0; michael@0: michael@0: virtual GLsizei getMaxSupportedSamples() const = 0; michael@0: michael@0: virtual unsigned int getMaxRenderTargets() const = 0; michael@0: michael@0: // Pixel operations michael@0: virtual bool copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source) = 0; michael@0: virtual bool copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source) = 0; michael@0: michael@0: virtual bool copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat, michael@0: GLint xoffset, GLint yoffset, TextureStorageInterface2D *storage, GLint level) = 0; michael@0: virtual bool copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat, michael@0: GLint xoffset, GLint yoffset, TextureStorageInterfaceCube *storage, GLenum target, GLint level) = 0; michael@0: michael@0: virtual bool blitRect(gl::Framebuffer *readTarget, const gl::Rectangle &readRect, gl::Framebuffer *drawTarget, const gl::Rectangle &drawRect, michael@0: bool blitRenderTarget, bool blitDepthStencil) = 0; michael@0: virtual void readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, michael@0: GLsizei outputPitch, bool packReverseRowOrder, GLint packAlignment, void* pixels) = 0; michael@0: michael@0: // RenderTarget creation michael@0: virtual RenderTarget *createRenderTarget(SwapChain *swapChain, bool depth) = 0; michael@0: virtual RenderTarget *createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth) = 0; michael@0: michael@0: // Shader operations michael@0: virtual ShaderExecutable *loadExecutable(const void *function, size_t length, rx::ShaderType type) = 0; michael@0: virtual ShaderExecutable *compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, rx::ShaderType type) = 0; michael@0: michael@0: // Image operations michael@0: virtual Image *createImage() = 0; michael@0: virtual void generateMipmap(Image *dest, Image *source) = 0; michael@0: virtual TextureStorage *createTextureStorage2D(SwapChain *swapChain) = 0; michael@0: virtual TextureStorage *createTextureStorage2D(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, GLsizei width, GLsizei height) = 0; michael@0: virtual TextureStorage *createTextureStorageCube(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, int size) = 0; michael@0: michael@0: // Buffer creation michael@0: virtual VertexBuffer *createVertexBuffer() = 0; michael@0: virtual IndexBuffer *createIndexBuffer() = 0; michael@0: virtual BufferStorage *createBufferStorage() = 0; michael@0: michael@0: // Query and Fence creation michael@0: virtual QueryImpl *createQuery(GLenum type) = 0; michael@0: virtual FenceImpl *createFence() = 0; michael@0: michael@0: virtual bool getLUID(LUID *adapterLuid) const = 0; michael@0: michael@0: protected: michael@0: bool initializeCompiler(); michael@0: ShaderBlob *compileToBinary(gl::InfoLog &infoLog, const char *hlsl, const char *profile, UINT optimizationFlags, bool alternateFlags); michael@0: michael@0: egl::Display *mDisplay; michael@0: michael@0: private: michael@0: DISALLOW_COPY_AND_ASSIGN(Renderer); michael@0: michael@0: HMODULE mD3dCompilerModule; michael@0: pCompileFunc mD3DCompileFunc; michael@0: }; michael@0: michael@0: } michael@0: #endif // LIBGLESV2_RENDERER_RENDERER_H_