blob: dab8d3b9f959f3e89e8a9a81e2d6813fd52994fa [file] [log] [blame]
daniel@transgaming.com621ce052012-10-31 17:52:29 +00001//
daniel@transgaming.coma390e1e2013-01-11 04:09:39 +00002// Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com621ce052012-10-31 17:52:29 +00003// 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
daniel@transgaming.com621ce052012-10-31 17:52:29 +000013#define GL_APICALL
14#include <GLES2/gl2.h>
15#include <GLES2/gl2ext.h>
16#define EGLAPI
17#include <EGL/egl.h>
18
daniel@transgaming.com25e16af2012-11-28 21:05:57 +000019#include <D3Dcompiler.h>
20
daniel@transgaming.comba0570e2012-10-31 18:07:39 +000021#include "libGLESv2/Texture.h"
daniel@transgaming.comab1c1462012-12-20 21:08:30 +000022#include "libGLESv2/Uniform.h"
daniel@transgaming.comef19da52012-11-28 19:35:08 +000023#include "libGLESv2/angletypes.h"
daniel@transgaming.come4733d72012-10-31 18:07:01 +000024
daniel@transgaming.coma9c71422012-11-28 20:58:45 +000025#include "libGLESv2/renderer/ShaderExecutable.h"
26
daniel@transgaming.com621ce052012-10-31 17:52:29 +000027const int versionWindowsVista = MAKEWORD(0x00, 0x06);
28const int versionWindows7 = MAKEWORD(0x01, 0x06);
29
30// Return the version of the operating system in a format suitable for ordering
31// comparison.
32inline int getComparableOSVersion()
33{
34 DWORD version = GetVersion();
35 int majorVersion = LOBYTE(LOWORD(version));
36 int minorVersion = HIBYTE(LOWORD(version));
37 return MAKEWORD(minorVersion, majorVersion);
38}
39
daniel@transgaming.comef21ab22012-10-31 17:52:47 +000040namespace egl
41{
42class Display;
43}
44
daniel@transgaming.com83e80ee2012-11-28 19:40:53 +000045namespace gl
46{
daniel@transgaming.coma9c71422012-11-28 20:58:45 +000047class InfoLog;
daniel@transgaming.com83e80ee2012-11-28 19:40:53 +000048class ProgramBinary;
daniel@transgaming.com67094ee2012-11-28 20:53:04 +000049class VertexAttribute;
daniel@transgaming.com91207b72012-11-28 20:56:43 +000050class Buffer;
daniel@transgaming.com83e80ee2012-11-28 19:40:53 +000051}
52
daniel@transgaming.com31b13e12012-11-28 19:34:30 +000053namespace rx
daniel@transgaming.com1d80eee2012-11-28 19:33:31 +000054{
daniel@transgaming.com87705f82012-12-20 21:10:45 +000055class TextureStorageInterface2D;
56class TextureStorageInterfaceCube;
daniel@transgaming.com3f255b42012-12-20 21:07:35 +000057class VertexBuffer;
daniel@transgaming.com0b6d7742012-12-20 21:09:47 +000058class IndexBuffer;
daniel@transgaming.comde8a7ff2012-11-28 19:34:13 +000059class Blit;
daniel@transgaming.com31240482012-11-28 21:06:41 +000060struct TranslatedIndexData;
daniel@transgaming.comde8a7ff2012-11-28 19:34:13 +000061
daniel@transgaming.com3281f972012-10-31 18:38:51 +000062struct ConfigDesc
63{
64 GLenum renderTargetFormat;
65 GLenum depthStencilFormat;
66 GLint multiSample;
67 bool fastConfig;
68};
69
daniel@transgaming.coma390e1e2013-01-11 04:09:39 +000070struct dx_VertexConstants
71{
72 float depthRange[4];
73 float halfPixelSize[4];
74};
75
76struct dx_PixelConstants
77{
78 float depthRange[4];
79 float coord[4];
80 float depthFront[4];
81};
82
daniel@transgaming.com621ce052012-10-31 17:52:29 +000083class Renderer
84{
85 public:
daniel@transgaming.com25e16af2012-11-28 21:05:57 +000086 explicit Renderer(egl::Display *display);
87 virtual ~Renderer();
daniel@transgaming.com621ce052012-10-31 17:52:29 +000088
daniel@transgaming.com2507f412012-10-31 18:46:48 +000089 virtual EGLint initialize() = 0;
90 virtual bool resetDevice() = 0;
daniel@transgaming.com621ce052012-10-31 17:52:29 +000091
daniel@transgaming.com2507f412012-10-31 18:46:48 +000092 virtual int generateConfigs(ConfigDesc **configDescList) = 0;
93 virtual void deleteConfigs(ConfigDesc *configDescList) = 0;
daniel@transgaming.com3281f972012-10-31 18:38:51 +000094
daniel@transgaming.com2507f412012-10-31 18:46:48 +000095 virtual void sync(bool block) = 0;
daniel@transgaming.comef21ab22012-10-31 17:52:47 +000096
daniel@transgaming.comb9bb2792012-11-28 19:36:49 +000097 virtual SwapChain *createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) = 0;
98
daniel@transgaming.com2507f412012-10-31 18:46:48 +000099 virtual void setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler) = 0;
100 virtual void setTexture(gl::SamplerType type, int index, gl::Texture *texture) = 0;
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000101
daniel@transgaming.com237bc7e2012-11-28 21:01:06 +0000102 virtual void setRasterizerState(const gl::RasterizerState &rasterState) = 0;
daniel@transgaming.com493d4f82012-11-28 19:35:45 +0000103 virtual void setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor,
104 unsigned int sampleMask) = 0;
daniel@transgaming.com08c331d2012-11-28 19:38:39 +0000105 virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
daniel@transgaming.com3a0ef482012-11-28 21:01:20 +0000106 int stencilBackRef, bool frontFaceCCW) = 0;
daniel@transgaming.com493d4f82012-11-28 19:35:45 +0000107
daniel@transgaming.comd55e8c12012-11-28 21:07:02 +0000108 virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled) = 0;
daniel@transgaming.com12985182012-12-20 20:56:31 +0000109 virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
110 bool ignoreViewport, gl::ProgramBinary *currentProgram, bool forceSetUniforms) = 0;
daniel@transgaming.com493d4f82012-11-28 19:35:45 +0000111
daniel@transgaming.comae39ee22012-11-28 19:42:02 +0000112 virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer) = 0;
daniel@transgaming.com5fbf1772012-11-28 20:54:43 +0000113 virtual void applyShaders(gl::ProgramBinary *programBinary) = 0;
daniel@transgaming.coma390e1e2013-01-11 04:09:39 +0000114 virtual void applyUniforms(const gl::UniformArray *uniformArray, const dx_VertexConstants &vertexConstants, const dx_PixelConstants &pixelConstants) = 0;
daniel@transgaming.com91207b72012-11-28 20:56:43 +0000115 virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 0;
116 virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances) = 0;
daniel@transgaming.com31240482012-11-28 21:06:41 +0000117 virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, TranslatedIndexData *indexInfo) = 0;
daniel@transgaming.com493d4f82012-11-28 19:35:45 +0000118
daniel@transgaming.com91207b72012-11-28 20:56:43 +0000119 virtual void drawArrays(GLenum mode, GLsizei count, GLsizei instances) = 0;
daniel@transgaming.com31240482012-11-28 21:06:41 +0000120 virtual void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo) = 0;
daniel@transgaming.com67094ee2012-11-28 20:53:04 +0000121
daniel@transgaming.com084a2572012-11-28 20:55:17 +0000122 virtual void clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) = 0;
daniel@transgaming.comd084c622012-11-28 19:36:05 +0000123
daniel@transgaming.comc43a6052012-11-28 19:41:51 +0000124 virtual void markAllStateDirty() = 0;
125
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000126 // lost device
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000127 virtual void markDeviceLost() = 0;
128 virtual bool isDeviceLost() = 0;
129 virtual bool testDeviceLost(bool notify) = 0;
130 virtual bool testDeviceResettable() = 0;
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000131
132 // Renderer capabilities
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000133 virtual DWORD getAdapterVendor() const = 0;
134 virtual const char *getAdapterDescription() const = 0;
135 virtual GUID getAdapterIdentifier() const = 0;
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000136
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000137 virtual bool getDXT1TextureSupport() = 0;
138 virtual bool getDXT3TextureSupport() = 0;
139 virtual bool getDXT5TextureSupport() = 0;
140 virtual bool getEventQuerySupport() = 0;
141 virtual bool getFloat32TextureSupport(bool *filtering, bool *renderable) = 0;
142 virtual bool getFloat16TextureSupport(bool *filtering, bool *renderable) = 0;
143 virtual bool getLuminanceTextureSupport() = 0;
144 virtual bool getLuminanceAlphaTextureSupport() = 0;
145 virtual bool getVertexTextureSupport() const = 0;
146 virtual bool getNonPower2TextureSupport() const = 0;
147 virtual bool getDepthTextureSupport() const = 0;
148 virtual bool getOcclusionQuerySupport() const = 0;
149 virtual bool getInstancingSupport() const = 0;
150 virtual bool getTextureFilterAnisotropySupport() const = 0;
151 virtual float getTextureMaxAnisotropy() const = 0;
152 virtual bool getShareHandleSupport() const = 0;
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000153
daniel@transgaming.com9549bea2012-11-28 20:57:23 +0000154 virtual int getMajorShaderModel() const = 0;
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000155 virtual float getMaxPointSize() const = 0;
156 virtual int getMaxTextureWidth() const = 0;
157 virtual int getMaxTextureHeight() const = 0;
158 virtual bool get32BitIndexSupport() const = 0;
159 virtual int getMinSwapInterval() const = 0;
160 virtual int getMaxSwapInterval() const = 0;
daniel@transgaming.com5f4c1362012-10-31 18:29:00 +0000161
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000162 virtual GLsizei getMaxSupportedSamples() const = 0;
daniel@transgaming.comb7833982012-10-31 18:31:46 +0000163
daniel@transgaming.coma9c71422012-11-28 20:58:45 +0000164 // Pixel operations
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000165 virtual bool copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source) = 0;
166 virtual bool copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source) = 0;
daniel@transgaming.com1d80eee2012-11-28 19:33:31 +0000167
daniel@transgaming.com38380882012-11-28 19:36:39 +0000168 virtual bool copyImage(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat,
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000169 GLint xoffset, GLint yoffset, TextureStorageInterface2D *storage, GLint level) = 0;
daniel@transgaming.com38380882012-11-28 19:36:39 +0000170 virtual bool copyImage(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat,
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000171 GLint xoffset, GLint yoffset, TextureStorageInterfaceCube *storage, GLenum target, GLint level) = 0;
daniel@transgaming.comde8a7ff2012-11-28 19:34:13 +0000172
daniel@transgaming.com6c872172012-11-28 19:39:33 +0000173 virtual bool blitRect(gl::Framebuffer *readTarget, gl::Rectangle *readRect, gl::Framebuffer *drawTarget, gl::Rectangle *drawRect,
174 bool blitRenderTarget, bool blitDepthStencil) = 0;
175 virtual void readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type,
176 GLsizei outputPitch, bool packReverseRowOrder, GLint packAlignment, void* pixels) = 0;
177
daniel@transgaming.coma9c71422012-11-28 20:58:45 +0000178 // RenderTarget creation
daniel@transgaming.comf2423652012-11-28 20:53:50 +0000179 virtual RenderTarget *createRenderTarget(SwapChain *swapChain, bool depth) = 0;
180 virtual RenderTarget *createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth) = 0;
181
daniel@transgaming.coma9c71422012-11-28 20:58:45 +0000182 // Shader operations
daniel@transgaming.com2275f912012-12-20 21:13:22 +0000183 virtual ShaderExecutable *loadExecutable(const void *function, size_t length, GLenum type) = 0;
daniel@transgaming.coma9c71422012-11-28 20:58:45 +0000184 virtual ShaderExecutable *compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, GLenum type) = 0;
185
daniel@transgaming.comf721fdb2012-12-20 20:53:11 +0000186 // Image operations
daniel@transgaming.com244e1832012-12-20 20:52:35 +0000187 virtual Image *createImage() = 0;
daniel@transgaming.comf721fdb2012-12-20 20:53:11 +0000188 virtual void generateMipmap(Image *dest, Image *source) = 0;
daniel@transgaming.com413d2712012-12-20 21:11:04 +0000189 virtual TextureStorage *createTextureStorage2D(SwapChain *swapChain) = 0;
190 virtual TextureStorage *createTextureStorage2D(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, GLsizei width, GLsizei height) = 0;
191 virtual TextureStorage *createTextureStorageCube(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, int size) = 0;
daniel@transgaming.com244e1832012-12-20 20:52:35 +0000192
daniel@transgaming.com3f255b42012-12-20 21:07:35 +0000193 // Buffer creation
194 virtual VertexBuffer *createVertexBuffer() = 0;
daniel@transgaming.com0b6d7742012-12-20 21:09:47 +0000195 virtual IndexBuffer *createIndexBuffer() = 0;
daniel@transgaming.com3f255b42012-12-20 21:07:35 +0000196
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000197 protected:
daniel@transgaming.com25e16af2012-11-28 21:05:57 +0000198 bool initializeCompiler();
199 ID3DBlob *compileToBinary(gl::InfoLog &infoLog, const char *hlsl, const char *profile, bool alternateFlags);
200
daniel@transgaming.comef21ab22012-10-31 17:52:47 +0000201 egl::Display *mDisplay;
daniel@transgaming.com4f0af572012-10-31 19:55:46 +0000202
203 private:
204 DISALLOW_COPY_AND_ASSIGN(Renderer);
205
daniel@transgaming.com25e16af2012-11-28 21:05:57 +0000206 HMODULE mD3dCompilerModule;
207 pD3DCompile mD3DCompileFunc;
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000208};
209
210}
211#endif // LIBGLESV2_RENDERER_RENDERER_H_