blob: 65e83a93a4a96b6f44dcd449062c21874cf67ca6 [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.comab1c1462012-12-20 21:08:30 +000013#include "libGLESv2/Uniform.h"
daniel@transgaming.comef19da52012-11-28 19:35:08 +000014#include "libGLESv2/angletypes.h"
daniel@transgaming.come4733d72012-10-31 18:07:01 +000015
daniel@transgaming.com621ce052012-10-31 17:52:29 +000016const int versionWindowsVista = MAKEWORD(0x00, 0x06);
17const int versionWindows7 = MAKEWORD(0x01, 0x06);
18
19// Return the version of the operating system in a format suitable for ordering
20// comparison.
21inline int getComparableOSVersion()
22{
23 DWORD version = GetVersion();
24 int majorVersion = LOBYTE(LOWORD(version));
25 int minorVersion = HIBYTE(LOWORD(version));
26 return MAKEWORD(minorVersion, majorVersion);
27}
28
daniel@transgaming.comef21ab22012-10-31 17:52:47 +000029namespace egl
30{
31class Display;
32}
33
daniel@transgaming.com83e80ee2012-11-28 19:40:53 +000034namespace gl
35{
daniel@transgaming.coma9c71422012-11-28 20:58:45 +000036class InfoLog;
daniel@transgaming.com83e80ee2012-11-28 19:40:53 +000037class ProgramBinary;
daniel@transgaming.com67094ee2012-11-28 20:53:04 +000038class VertexAttribute;
daniel@transgaming.com91207b72012-11-28 20:56:43 +000039class Buffer;
shannon.woods@transgaming.comd2811d62013-02-28 23:11:19 +000040class Texture;
41class Framebuffer;
daniel@transgaming.com83e80ee2012-11-28 19:40:53 +000042}
43
daniel@transgaming.com31b13e12012-11-28 19:34:30 +000044namespace rx
daniel@transgaming.com1d80eee2012-11-28 19:33:31 +000045{
daniel@transgaming.com87705f82012-12-20 21:10:45 +000046class TextureStorageInterface2D;
47class TextureStorageInterfaceCube;
shannon.woods%transgaming.com@gtempaccount.com414e82a2013-04-13 03:44:05 +000048class TextureStorageInterface3D;
daniel@transgaming.com3f255b42012-12-20 21:07:35 +000049class VertexBuffer;
daniel@transgaming.com0b6d7742012-12-20 21:09:47 +000050class IndexBuffer;
shannon.woods@transgaming.com50df6c52013-02-28 23:02:49 +000051class QueryImpl;
shannon.woods@transgaming.comcfe787e2013-02-28 23:03:35 +000052class FenceImpl;
shannon.woods@transgaming.com4e52b632013-02-28 23:08:01 +000053class BufferStorage;
daniel@transgaming.comde8a7ff2012-11-28 19:34:13 +000054class Blit;
daniel@transgaming.com31240482012-11-28 21:06:41 +000055struct TranslatedIndexData;
shannon.woods@transgaming.comd2811d62013-02-28 23:11:19 +000056class ShaderExecutable;
57class SwapChain;
58class RenderTarget;
59class Image;
60class TextureStorage;
daniel@transgaming.comde8a7ff2012-11-28 19:34:13 +000061
shannon.woods@transgaming.com4e91d562013-02-28 23:12:09 +000062typedef void * ShaderBlob;
63typedef void (*pCompileFunc)();
64
daniel@transgaming.com3281f972012-10-31 18:38:51 +000065struct ConfigDesc
66{
67 GLenum renderTargetFormat;
68 GLenum depthStencilFormat;
69 GLint multiSample;
70 bool fastConfig;
shannon.woods%transgaming.com@gtempaccount.comdcf33d52013-04-13 03:33:11 +000071 bool es3Capable;
daniel@transgaming.com3281f972012-10-31 18:38:51 +000072};
73
daniel@transgaming.coma390e1e2013-01-11 04:09:39 +000074struct dx_VertexConstants
75{
76 float depthRange[4];
shannon.woods@transgaming.com42832a62013-02-28 23:18:38 +000077 float viewAdjust[4];
daniel@transgaming.coma390e1e2013-01-11 04:09:39 +000078};
79
80struct dx_PixelConstants
81{
82 float depthRange[4];
shannon.woods@transgaming.coma14ecf32013-02-28 23:09:42 +000083 float viewCoords[4];
daniel@transgaming.coma390e1e2013-01-11 04:09:39 +000084 float depthFront[4];
85};
86
shannon.woods@transgaming.com69ff7762013-01-25 21:55:24 +000087enum ShaderType
88{
89 SHADER_VERTEX,
shannon.woods@transgaming.com3e773bb2013-01-25 21:55:47 +000090 SHADER_PIXEL,
91 SHADER_GEOMETRY
shannon.woods@transgaming.com69ff7762013-01-25 21:55:24 +000092};
93
daniel@transgaming.com621ce052012-10-31 17:52:29 +000094class Renderer
95{
96 public:
daniel@transgaming.com25e16af2012-11-28 21:05:57 +000097 explicit Renderer(egl::Display *display);
98 virtual ~Renderer();
daniel@transgaming.com621ce052012-10-31 17:52:29 +000099
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000100 virtual EGLint initialize() = 0;
101 virtual bool resetDevice() = 0;
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000102
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000103 virtual int generateConfigs(ConfigDesc **configDescList) = 0;
104 virtual void deleteConfigs(ConfigDesc *configDescList) = 0;
daniel@transgaming.com3281f972012-10-31 18:38:51 +0000105
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000106 virtual void sync(bool block) = 0;
daniel@transgaming.comef21ab22012-10-31 17:52:47 +0000107
daniel@transgaming.comb9bb2792012-11-28 19:36:49 +0000108 virtual SwapChain *createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) = 0;
109
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000110 virtual void setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler) = 0;
111 virtual void setTexture(gl::SamplerType type, int index, gl::Texture *texture) = 0;
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000112
daniel@transgaming.com237bc7e2012-11-28 21:01:06 +0000113 virtual void setRasterizerState(const gl::RasterizerState &rasterState) = 0;
daniel@transgaming.com493d4f82012-11-28 19:35:45 +0000114 virtual void setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor,
115 unsigned int sampleMask) = 0;
daniel@transgaming.com08c331d2012-11-28 19:38:39 +0000116 virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
daniel@transgaming.com3a0ef482012-11-28 21:01:20 +0000117 int stencilBackRef, bool frontFaceCCW) = 0;
daniel@transgaming.com493d4f82012-11-28 19:35:45 +0000118
daniel@transgaming.comd55e8c12012-11-28 21:07:02 +0000119 virtual void setScissorRectangle(const gl::Rectangle &scissor, bool enabled) = 0;
daniel@transgaming.com12985182012-12-20 20:56:31 +0000120 virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace,
shannon.woods@transgaming.com0b236e22013-01-25 21:57:07 +0000121 bool ignoreViewport) = 0;
daniel@transgaming.com493d4f82012-11-28 19:35:45 +0000122
daniel@transgaming.comae39ee22012-11-28 19:42:02 +0000123 virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer) = 0;
daniel@transgaming.com5fbf1772012-11-28 20:54:43 +0000124 virtual void applyShaders(gl::ProgramBinary *programBinary) = 0;
shannon.woods@transgaming.com21ba6472013-01-25 21:53:32 +0000125 virtual void applyUniforms(gl::ProgramBinary *programBinary, gl::UniformArray *uniformArray) = 0;
daniel@transgaming.com91207b72012-11-28 20:56:43 +0000126 virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 0;
127 virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances) = 0;
daniel@transgaming.com31240482012-11-28 21:06:41 +0000128 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 +0000129
daniel@transgaming.com91207b72012-11-28 20:56:43 +0000130 virtual void drawArrays(GLenum mode, GLsizei count, GLsizei instances) = 0;
shannon.woods@transgaming.com00032cb2013-01-25 21:56:30 +0000131 virtual void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, gl::Buffer *elementArrayBuffer, const TranslatedIndexData &indexInfo, GLsizei instances) = 0;
daniel@transgaming.com67094ee2012-11-28 20:53:04 +0000132
daniel@transgaming.com084a2572012-11-28 20:55:17 +0000133 virtual void clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) = 0;
daniel@transgaming.comd084c622012-11-28 19:36:05 +0000134
daniel@transgaming.comc43a6052012-11-28 19:41:51 +0000135 virtual void markAllStateDirty() = 0;
136
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000137 // lost device
shannon.woods@transgaming.comeb049e22013-02-28 23:04:49 +0000138 virtual void notifyDeviceLost() = 0;
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000139 virtual bool isDeviceLost() = 0;
140 virtual bool testDeviceLost(bool notify) = 0;
141 virtual bool testDeviceResettable() = 0;
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000142
143 // Renderer capabilities
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000144 virtual DWORD getAdapterVendor() const = 0;
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000145 virtual std::string getRendererDescription() const = 0;
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000146 virtual GUID getAdapterIdentifier() const = 0;
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000147
shannon.woods@transgaming.combec04bf2013-01-25 21:53:52 +0000148 virtual bool getBGRATextureSupport() const = 0;
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000149 virtual bool getDXT1TextureSupport() = 0;
150 virtual bool getDXT3TextureSupport() = 0;
151 virtual bool getDXT5TextureSupport() = 0;
152 virtual bool getEventQuerySupport() = 0;
153 virtual bool getFloat32TextureSupport(bool *filtering, bool *renderable) = 0;
154 virtual bool getFloat16TextureSupport(bool *filtering, bool *renderable) = 0;
155 virtual bool getLuminanceTextureSupport() = 0;
156 virtual bool getLuminanceAlphaTextureSupport() = 0;
shannon.woods@transgaming.com233fe952013-01-25 21:51:57 +0000157 bool getVertexTextureSupport() const { return getMaxVertexTextureImageUnits() > 0; }
158 virtual unsigned int getMaxVertexTextureImageUnits() const = 0;
shannon.woods@transgaming.com76cd88c2013-01-25 21:54:36 +0000159 virtual unsigned int getMaxCombinedTextureImageUnits() const = 0;
shannon.woods@transgaming.comd8136cb2013-02-28 23:14:44 +0000160 virtual unsigned int getReservedVertexUniformVectors() const = 0;
161 virtual unsigned int getReservedFragmentUniformVectors() const = 0;
162 virtual unsigned int getMaxVertexUniformVectors() const = 0;
163 virtual unsigned int getMaxFragmentUniformVectors() const = 0;
164 virtual unsigned int getMaxVaryingVectors() const = 0;
shannon.woods%transgaming.com@gtempaccount.com3f72ce32013-04-13 03:36:43 +0000165 virtual unsigned int getMaxVertexShaderUniformBuffers() const = 0;
166 virtual unsigned int getMaxFragmentShaderUniformBuffers() const = 0;
167 virtual unsigned int getMaxTransformFeedbackBuffers() const = 0;
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000168 virtual bool getNonPower2TextureSupport() const = 0;
169 virtual bool getDepthTextureSupport() const = 0;
170 virtual bool getOcclusionQuerySupport() const = 0;
171 virtual bool getInstancingSupport() const = 0;
172 virtual bool getTextureFilterAnisotropySupport() const = 0;
173 virtual float getTextureMaxAnisotropy() const = 0;
174 virtual bool getShareHandleSupport() const = 0;
daniel@transgaming.com7629bb62013-01-11 04:12:28 +0000175 virtual bool getDerivativeInstructionSupport() const = 0;
shannon.woods@transgaming.com8d2f0862013-02-28 23:09:19 +0000176 virtual bool getPostSubBufferSupport() const = 0;
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000177
daniel@transgaming.com9549bea2012-11-28 20:57:23 +0000178 virtual int getMajorShaderModel() const = 0;
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000179 virtual float getMaxPointSize() const = 0;
shannon.woods@transgaming.com8ce2f8f2013-02-28 23:07:10 +0000180 virtual int getMaxViewportDimension() const = 0;
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000181 virtual int getMaxTextureWidth() const = 0;
182 virtual int getMaxTextureHeight() const = 0;
183 virtual bool get32BitIndexSupport() const = 0;
184 virtual int getMinSwapInterval() const = 0;
185 virtual int getMaxSwapInterval() const = 0;
daniel@transgaming.com5f4c1362012-10-31 18:29:00 +0000186
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000187 virtual GLsizei getMaxSupportedSamples() const = 0;
daniel@transgaming.comb7833982012-10-31 18:31:46 +0000188
shannon.woods%transgaming.com@gtempaccount.comb290ac12013-04-13 03:28:15 +0000189 virtual unsigned int getMaxRenderTargets() const = 0;
190
daniel@transgaming.coma9c71422012-11-28 20:58:45 +0000191 // Pixel operations
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000192 virtual bool copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source) = 0;
193 virtual bool copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source) = 0;
shannon.woods%transgaming.com@gtempaccount.com414e82a2013-04-13 03:44:05 +0000194 virtual bool copyToRenderTarget(TextureStorageInterface3D *dest, TextureStorageInterface3D *source) = 0;
daniel@transgaming.com1d80eee2012-11-28 19:33:31 +0000195
shannon.woods@transgaming.com664916b2013-01-25 21:50:32 +0000196 virtual bool copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000197 GLint xoffset, GLint yoffset, TextureStorageInterface2D *storage, GLint level) = 0;
shannon.woods@transgaming.com664916b2013-01-25 21:50:32 +0000198 virtual bool copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
daniel@transgaming.com87705f82012-12-20 21:10:45 +0000199 GLint xoffset, GLint yoffset, TextureStorageInterfaceCube *storage, GLenum target, GLint level) = 0;
shannon.woods%transgaming.com@gtempaccount.com414e82a2013-04-13 03:44:05 +0000200 virtual bool copyImage(gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat,
201 GLint xoffset, GLint yoffset, GLint zOffset, TextureStorageInterface3D *storage, GLint level) = 0;
daniel@transgaming.comde8a7ff2012-11-28 19:34:13 +0000202
shannon.woods@transgaming.comea4a0c62013-02-28 23:06:29 +0000203 virtual bool blitRect(gl::Framebuffer *readTarget, const gl::Rectangle &readRect, gl::Framebuffer *drawTarget, const gl::Rectangle &drawRect,
daniel@transgaming.com6c872172012-11-28 19:39:33 +0000204 bool blitRenderTarget, bool blitDepthStencil) = 0;
205 virtual void readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type,
206 GLsizei outputPitch, bool packReverseRowOrder, GLint packAlignment, void* pixels) = 0;
207
daniel@transgaming.coma9c71422012-11-28 20:58:45 +0000208 // RenderTarget creation
daniel@transgaming.comf2423652012-11-28 20:53:50 +0000209 virtual RenderTarget *createRenderTarget(SwapChain *swapChain, bool depth) = 0;
210 virtual RenderTarget *createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth) = 0;
211
daniel@transgaming.coma9c71422012-11-28 20:58:45 +0000212 // Shader operations
shannon.woods@transgaming.com69ff7762013-01-25 21:55:24 +0000213 virtual ShaderExecutable *loadExecutable(const void *function, size_t length, rx::ShaderType type) = 0;
214 virtual ShaderExecutable *compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, rx::ShaderType type) = 0;
daniel@transgaming.coma9c71422012-11-28 20:58:45 +0000215
daniel@transgaming.comf721fdb2012-12-20 20:53:11 +0000216 // Image operations
daniel@transgaming.com244e1832012-12-20 20:52:35 +0000217 virtual Image *createImage() = 0;
daniel@transgaming.comf721fdb2012-12-20 20:53:11 +0000218 virtual void generateMipmap(Image *dest, Image *source) = 0;
daniel@transgaming.com413d2712012-12-20 21:11:04 +0000219 virtual TextureStorage *createTextureStorage2D(SwapChain *swapChain) = 0;
220 virtual TextureStorage *createTextureStorage2D(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, GLsizei width, GLsizei height) = 0;
221 virtual TextureStorage *createTextureStorageCube(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, int size) = 0;
shannon.woods%transgaming.com@gtempaccount.com2058d642013-04-13 03:42:50 +0000222 virtual TextureStorage *createTextureStorage3D(int levels, GLenum internalformat, GLenum usage, GLsizei width, GLsizei height, GLsizei depth) = 0;
daniel@transgaming.com244e1832012-12-20 20:52:35 +0000223
daniel@transgaming.com3f255b42012-12-20 21:07:35 +0000224 // Buffer creation
225 virtual VertexBuffer *createVertexBuffer() = 0;
daniel@transgaming.com0b6d7742012-12-20 21:09:47 +0000226 virtual IndexBuffer *createIndexBuffer() = 0;
shannon.woods@transgaming.com4e52b632013-02-28 23:08:01 +0000227 virtual BufferStorage *createBufferStorage() = 0;
daniel@transgaming.com3f255b42012-12-20 21:07:35 +0000228
shannon.woods@transgaming.comcfe787e2013-02-28 23:03:35 +0000229 // Query and Fence creation
shannon.woods@transgaming.com50df6c52013-02-28 23:02:49 +0000230 virtual QueryImpl *createQuery(GLenum type) = 0;
shannon.woods@transgaming.comcfe787e2013-02-28 23:03:35 +0000231 virtual FenceImpl *createFence() = 0;
shannon.woods@transgaming.com50df6c52013-02-28 23:02:49 +0000232
shannon.woods%transgaming.com@gtempaccount.com785f1962013-04-13 03:34:45 +0000233 // Current GLES client version
234 void setCurrentClientVersion(int clientVersion) { mCurrentClientVersion = clientVersion; }
235 int getCurrentClientVersion() const { return mCurrentClientVersion; }
236
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000237 protected:
daniel@transgaming.com25e16af2012-11-28 21:05:57 +0000238 bool initializeCompiler();
shannon.woods@transgaming.comd3d42082013-02-28 23:14:31 +0000239 ShaderBlob *compileToBinary(gl::InfoLog &infoLog, const char *hlsl, const char *profile, UINT optimizationFlags, bool alternateFlags);
daniel@transgaming.com25e16af2012-11-28 21:05:57 +0000240
daniel@transgaming.comef21ab22012-10-31 17:52:47 +0000241 egl::Display *mDisplay;
daniel@transgaming.com4f0af572012-10-31 19:55:46 +0000242
243 private:
244 DISALLOW_COPY_AND_ASSIGN(Renderer);
245
daniel@transgaming.com25e16af2012-11-28 21:05:57 +0000246 HMODULE mD3dCompilerModule;
shannon.woods@transgaming.com4e91d562013-02-28 23:12:09 +0000247 pCompileFunc mD3DCompileFunc;
shannon.woods%transgaming.com@gtempaccount.com785f1962013-04-13 03:34:45 +0000248 int mCurrentClientVersion;
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000249};
250
251}
252#endif // LIBGLESV2_RENDERER_RENDERER_H_