Home | History | Annotate | Download | only in renderer
      1 //
      2 // Copyright (c) 2012-2014 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 #include "libGLESv2/Caps.h"
     16 #include "libGLESv2/Error.h"
     17 
     18 #include <cstdint>
     19 
     20 #include <EGL/egl.h>
     21 
     22 #if !defined(ANGLE_COMPILE_OPTIMIZATION_LEVEL)
     23 // WARNING: D3DCOMPILE_OPTIMIZATION_LEVEL3 may lead to a DX9 shader compiler hang.
     24 // It should only be used selectively to work around specific bugs.
     25 #define ANGLE_COMPILE_OPTIMIZATION_LEVEL D3DCOMPILE_OPTIMIZATION_LEVEL1
     26 #endif
     27 
     28 namespace egl
     29 {
     30 class Display;
     31 }
     32 
     33 namespace gl
     34 {
     35 class InfoLog;
     36 class ProgramBinary;
     37 struct LinkedVarying;
     38 struct VertexAttribute;
     39 class Buffer;
     40 class Texture;
     41 class Framebuffer;
     42 struct VertexAttribCurrentValueData;
     43 }
     44 
     45 namespace rx
     46 {
     47 class TextureStorage;
     48 class VertexBuffer;
     49 class IndexBuffer;
     50 class QueryImpl;
     51 class FenceImpl;
     52 class BufferImpl;
     53 class VertexArrayImpl;
     54 class BufferStorage;
     55 struct TranslatedIndexData;
     56 class ShaderImpl;
     57 class ProgramImpl;
     58 class ShaderExecutable;
     59 class SwapChain;
     60 class RenderTarget;
     61 class Image;
     62 class TextureStorage;
     63 class UniformStorage;
     64 class TextureImpl;
     65 class TransformFeedbackImpl;
     66 
     67 struct ConfigDesc
     68 {
     69     GLenum  renderTargetFormat;
     70     GLenum  depthStencilFormat;
     71     GLint   multiSample;
     72     bool    fastConfig;
     73     bool    es3Capable;
     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 generateSwizzle(gl::Texture *texture) = 0;
    113     virtual void setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler) = 0;
    114     virtual void setTexture(gl::SamplerType type, int index, gl::Texture *texture) = 0;
    115 
    116     virtual bool setUniformBuffers(const gl::Buffer *vertexUniformBuffers[], const gl::Buffer *fragmentUniformBuffers[]) = 0;
    117 
    118     virtual void setRasterizerState(const gl::RasterizerState &rasterState) = 0;
    119     virtual void setBlendState(gl::Framebuffer *framebuffer, const gl::BlendState &blendState, const gl::ColorF &blendColor,
    120                                unsigned int sampleMask) = 0;
    121     virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
    122                                       int stencilBackRef, bool frontFaceCCW) = 0;
    123 
    124     virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled) = 0;
    125     virtual void setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
    126                              bool ignoreViewport) = 0;
    127 
    128     virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer) = 0;
    129     virtual void applyShaders(gl::ProgramBinary *programBinary, const gl::VertexFormat inputLayout[], const gl::Framebuffer *framebuffer,
    130                               bool rasterizerDiscard, bool transformFeedbackActive) = 0;
    131     virtual void applyUniforms(const gl::ProgramBinary &programBinary) = 0;
    132     virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 0;
    133     virtual gl::Error applyVertexBuffer(gl::ProgramBinary *programBinary, const gl::VertexAttribute vertexAttributes[], const gl::VertexAttribCurrentValueData currentValues[],
    134                                         GLint first, GLsizei count, GLsizei instances) = 0;
    135     virtual gl::Error applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo) = 0;
    136     virtual void applyTransformFeedbackBuffers(gl::Buffer *transformFeedbackBuffers[], GLintptr offsets[]) = 0;
    137 
    138     virtual void drawArrays(GLenum mode, GLsizei count, GLsizei instances, bool transformFeedbackActive) = 0;
    139     virtual void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices,
    140                               gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances) = 0;
    141 
    142     virtual gl::Error clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) = 0;
    143 
    144     virtual void markAllStateDirty() = 0;
    145 
    146     // lost device
    147     virtual void notifyDeviceLost() = 0;
    148     virtual bool isDeviceLost() = 0;
    149     virtual bool testDeviceLost(bool notify) = 0;
    150     virtual bool testDeviceResettable() = 0;
    151 
    152     // Renderer capabilities (virtual because it is used by egl::Display, do not override)
    153     virtual const gl::Caps &getRendererCaps() const;
    154     virtual const gl::TextureCapsMap &getRendererTextureCaps() const;
    155     virtual const gl::Extensions &getRendererExtensions() const;
    156 
    157     virtual DWORD getAdapterVendor() const = 0;
    158     virtual std::string getRendererDescription() const = 0;
    159     virtual GUID getAdapterIdentifier() const = 0;
    160 
    161     virtual unsigned int getReservedVertexUniformVectors() const = 0;
    162     virtual unsigned int getReservedFragmentUniformVectors() const = 0;
    163     virtual unsigned int getReservedVertexUniformBuffers() const = 0;
    164     virtual unsigned int getReservedFragmentUniformBuffers() const = 0;
    165     virtual bool getShareHandleSupport() const = 0;
    166     virtual bool getPostSubBufferSupport() const = 0;
    167 
    168     virtual int getMajorShaderModel() const = 0;
    169     virtual int getMinSwapInterval() const = 0;
    170     virtual int getMaxSwapInterval() const = 0;
    171 
    172     // Pixel operations
    173     virtual bool copyToRenderTarget2D(TextureStorage *dest, TextureStorage *source) = 0;
    174     virtual bool copyToRenderTargetCube(TextureStorage *dest, TextureStorage *source) = 0;
    175     virtual bool copyToRenderTarget3D(TextureStorage *dest, TextureStorage *source) = 0;
    176     virtual bool copyToRenderTarget2DArray(TextureStorage *dest, TextureStorage *source) = 0;
    177 
    178     virtual bool copyImage2D(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
    179                              GLint xoffset, GLint yoffset, TextureStorage *storage, GLint level) = 0;
    180     virtual bool copyImageCube(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
    181                                GLint xoffset, GLint yoffset, TextureStorage *storage, GLenum target, GLint level) = 0;
    182     virtual bool copyImage3D(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
    183                              GLint xoffset, GLint yoffset, GLint zOffset, TextureStorage *storage, GLint level) = 0;
    184     virtual bool copyImage2DArray(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
    185                                   GLint xoffset, GLint yoffset, GLint zOffset, TextureStorage *storage, GLint level) = 0;
    186 
    187     virtual bool blitRect(gl::Framebuffer *readTarget, const gl::Rectangle &readRect, gl::Framebuffer *drawTarget, const gl::Rectangle &drawRect,
    188                           const gl::Rectangle *scissor, bool blitRenderTarget, bool blitDepth, bool blitStencil, GLenum filter) = 0;
    189 
    190     virtual gl::Error readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format,
    191                                  GLenum type, GLuint outputPitch, const gl::PixelPackState &pack, uint8_t *pixels) = 0;
    192 
    193     // RenderTarget creation
    194     virtual RenderTarget *createRenderTarget(SwapChain *swapChain, bool depth) = 0;
    195     virtual RenderTarget *createRenderTarget(int width, int height, GLenum format, GLsizei samples) = 0;
    196 
    197     // Shader creation
    198     virtual ShaderImpl *createShader(GLenum type) = 0;
    199     virtual ProgramImpl *createProgram() = 0;
    200 
    201     // Shader operations
    202     virtual void releaseShaderCompiler() = 0;
    203     virtual ShaderExecutable *loadExecutable(const void *function, size_t length, rx::ShaderType type,
    204                                              const std::vector<gl::LinkedVarying> &transformFeedbackVaryings,
    205                                              bool separatedOutputBuffers) = 0;
    206     virtual ShaderExecutable *compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, rx::ShaderType type,
    207                                                   const std::vector<gl::LinkedVarying> &transformFeedbackVaryings,
    208                                                   bool separatedOutputBuffers, D3DWorkaroundType workaround) = 0;
    209     virtual UniformStorage *createUniformStorage(size_t storageSize) = 0;
    210 
    211     // Image operations
    212     virtual Image *createImage() = 0;
    213     virtual void generateMipmap(Image *dest, Image *source) = 0;
    214     virtual TextureStorage *createTextureStorage2D(SwapChain *swapChain) = 0;
    215     virtual TextureStorage *createTextureStorage2D(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, int levels) = 0;
    216     virtual TextureStorage *createTextureStorageCube(GLenum internalformat, bool renderTarget, int size, int levels) = 0;
    217     virtual TextureStorage *createTextureStorage3D(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, GLsizei depth, int levels) = 0;
    218     virtual TextureStorage *createTextureStorage2DArray(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, GLsizei depth, int levels) = 0;
    219 
    220     // Texture creation
    221     virtual TextureImpl *createTexture(GLenum target) = 0;
    222 
    223     // Buffer creation
    224     virtual BufferImpl *createBuffer() = 0;
    225     virtual VertexBuffer *createVertexBuffer() = 0;
    226     virtual IndexBuffer *createIndexBuffer() = 0;
    227 
    228     // Vertex Array creation
    229     virtual VertexArrayImpl *createVertexArray() = 0;
    230 
    231     // Query and Fence creation
    232     virtual QueryImpl *createQuery(GLenum type) = 0;
    233     virtual FenceImpl *createFence() = 0;
    234 
    235     // Transform Feedback creation
    236     virtual TransformFeedbackImpl* createTransformFeedback() = 0;
    237 
    238     // Current GLES client version
    239     void setCurrentClientVersion(int clientVersion) { mCurrentClientVersion = clientVersion; }
    240     int getCurrentClientVersion() const { return mCurrentClientVersion; }
    241 
    242     // Buffer-to-texture and Texture-to-buffer copies
    243     virtual bool supportsFastCopyBufferToTexture(GLenum internalFormat) const = 0;
    244     virtual bool fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
    245                                          GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea) = 0;
    246 
    247     virtual bool getLUID(LUID *adapterLuid) const = 0;
    248     virtual rx::VertexConversionType getVertexConversionType(const gl::VertexFormat &vertexFormat) const = 0;
    249     virtual GLenum getVertexComponentType(const gl::VertexFormat &vertexFormat) const = 0;
    250 
    251   protected:
    252     egl::Display *mDisplay;
    253 
    254   private:
    255     DISALLOW_COPY_AND_ASSIGN(Renderer);
    256 
    257     virtual void generateCaps(gl::Caps *outCaps, gl::TextureCapsMap* outTextureCaps, gl::Extensions *outExtensions) const = 0;
    258 
    259     mutable bool mCapsInitialized;
    260     mutable gl::Caps mCaps;
    261     mutable gl::TextureCapsMap mTextureCaps;
    262     mutable gl::Extensions mExtensions;
    263 
    264     int mCurrentClientVersion;
    265 };
    266 
    267 }
    268 #endif // LIBGLESV2_RENDERER_RENDERER_H_
    269