blob: c47fbe5aac7a491902f55fa416abb288848e570f [file] [log] [blame]
daniel@transgaming.com621ce052012-10-31 17:52:29 +00001//
2// Copyright (c) 2012 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
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.comba0570e2012-10-31 18:07:39 +000019#include "libGLESv2/Texture.h"
daniel@transgaming.comef19da52012-11-28 19:35:08 +000020#include "libGLESv2/angletypes.h"
daniel@transgaming.come4733d72012-10-31 18:07:01 +000021
daniel@transgaming.coma9c71422012-11-28 20:58:45 +000022#include "libGLESv2/renderer/ShaderExecutable.h"
23
daniel@transgaming.com621ce052012-10-31 17:52:29 +000024const int versionWindowsVista = MAKEWORD(0x00, 0x06);
25const int versionWindows7 = MAKEWORD(0x01, 0x06);
26
27// Return the version of the operating system in a format suitable for ordering
28// comparison.
29inline int getComparableOSVersion()
30{
31 DWORD version = GetVersion();
32 int majorVersion = LOBYTE(LOWORD(version));
33 int minorVersion = HIBYTE(LOWORD(version));
34 return MAKEWORD(minorVersion, majorVersion);
35}
36
daniel@transgaming.comef21ab22012-10-31 17:52:47 +000037namespace egl
38{
39class Display;
40}
41
daniel@transgaming.com83e80ee2012-11-28 19:40:53 +000042namespace gl
43{
daniel@transgaming.coma9c71422012-11-28 20:58:45 +000044class InfoLog;
daniel@transgaming.com83e80ee2012-11-28 19:40:53 +000045class ProgramBinary;
daniel@transgaming.com67094ee2012-11-28 20:53:04 +000046class VertexAttribute;
daniel@transgaming.com91207b72012-11-28 20:56:43 +000047class Buffer;
48struct TranslatedIndexData;
daniel@transgaming.com83e80ee2012-11-28 19:40:53 +000049}
50
daniel@transgaming.com31b13e12012-11-28 19:34:30 +000051namespace rx
daniel@transgaming.com1d80eee2012-11-28 19:33:31 +000052{
53class TextureStorage2D;
54class TextureStorageCubeMap;
daniel@transgaming.comde8a7ff2012-11-28 19:34:13 +000055class Blit;
56
daniel@transgaming.com3281f972012-10-31 18:38:51 +000057struct ConfigDesc
58{
59 GLenum renderTargetFormat;
60 GLenum depthStencilFormat;
61 GLint multiSample;
62 bool fastConfig;
63};
64
daniel@transgaming.com621ce052012-10-31 17:52:29 +000065class Renderer
66{
67 public:
daniel@transgaming.com4f0af572012-10-31 19:55:46 +000068 explicit Renderer(egl::Display *display) : mDisplay(display) {};
daniel@transgaming.com2507f412012-10-31 18:46:48 +000069 virtual ~Renderer() {};
daniel@transgaming.com621ce052012-10-31 17:52:29 +000070
daniel@transgaming.com2507f412012-10-31 18:46:48 +000071 virtual EGLint initialize() = 0;
72 virtual bool resetDevice() = 0;
daniel@transgaming.com621ce052012-10-31 17:52:29 +000073
daniel@transgaming.com2507f412012-10-31 18:46:48 +000074 virtual int generateConfigs(ConfigDesc **configDescList) = 0;
75 virtual void deleteConfigs(ConfigDesc *configDescList) = 0;
daniel@transgaming.com3281f972012-10-31 18:38:51 +000076
daniel@transgaming.com2507f412012-10-31 18:46:48 +000077 virtual void sync(bool block) = 0;
daniel@transgaming.comef21ab22012-10-31 17:52:47 +000078
daniel@transgaming.comb9bb2792012-11-28 19:36:49 +000079 virtual SwapChain *createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) = 0;
80
daniel@transgaming.com2507f412012-10-31 18:46:48 +000081 virtual void setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler) = 0;
82 virtual void setTexture(gl::SamplerType type, int index, gl::Texture *texture) = 0;
daniel@transgaming.com621ce052012-10-31 17:52:29 +000083
daniel@transgaming.com237bc7e2012-11-28 21:01:06 +000084 virtual void setRasterizerState(const gl::RasterizerState &rasterState) = 0;
daniel@transgaming.com493d4f82012-11-28 19:35:45 +000085 virtual void setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor,
86 unsigned int sampleMask) = 0;
daniel@transgaming.com08c331d2012-11-28 19:38:39 +000087 virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
daniel@transgaming.com3a0ef482012-11-28 21:01:20 +000088 int stencilBackRef, bool frontFaceCCW) = 0;
daniel@transgaming.com493d4f82012-11-28 19:35:45 +000089
daniel@transgaming.com04f1b332012-11-28 21:00:40 +000090 virtual void setScissorRectangle(const gl::Rectangle &scissor) = 0;
daniel@transgaming.come2f7b6b2012-11-28 21:00:51 +000091 virtual bool setViewport(const gl::Rectangle &viewport, float zNear, float zFar,
daniel@transgaming.com83e80ee2012-11-28 19:40:53 +000092 gl::ProgramBinary *currentProgram, bool forceSetUniforms) = 0;
daniel@transgaming.com493d4f82012-11-28 19:35:45 +000093
daniel@transgaming.comae39ee22012-11-28 19:42:02 +000094 virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer) = 0;
daniel@transgaming.com5fbf1772012-11-28 20:54:43 +000095 virtual void applyShaders(gl::ProgramBinary *programBinary) = 0;
daniel@transgaming.com91207b72012-11-28 20:56:43 +000096 virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 0;
97 virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances) = 0;
98 virtual GLenum applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, gl::TranslatedIndexData *indexInfo) = 0;
daniel@transgaming.com493d4f82012-11-28 19:35:45 +000099
daniel@transgaming.com91207b72012-11-28 20:56:43 +0000100 virtual void drawArrays(GLenum mode, GLsizei count, GLsizei instances) = 0;
daniel@transgaming.com97400dd2012-11-28 20:57:00 +0000101 virtual void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, gl::Buffer *elementArrayBuffer, const gl::TranslatedIndexData &indexInfo) = 0;
daniel@transgaming.com67094ee2012-11-28 20:53:04 +0000102
daniel@transgaming.com084a2572012-11-28 20:55:17 +0000103 virtual void clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) = 0;
daniel@transgaming.comd084c622012-11-28 19:36:05 +0000104
daniel@transgaming.comc43a6052012-11-28 19:41:51 +0000105 virtual void markAllStateDirty() = 0;
106
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000107 // lost device
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000108 virtual void markDeviceLost() = 0;
109 virtual bool isDeviceLost() = 0;
110 virtual bool testDeviceLost(bool notify) = 0;
111 virtual bool testDeviceResettable() = 0;
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000112
113 // Renderer capabilities
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000114 virtual DWORD getAdapterVendor() const = 0;
115 virtual const char *getAdapterDescription() const = 0;
116 virtual GUID getAdapterIdentifier() const = 0;
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000117
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000118 virtual bool getDXT1TextureSupport() = 0;
119 virtual bool getDXT3TextureSupport() = 0;
120 virtual bool getDXT5TextureSupport() = 0;
121 virtual bool getEventQuerySupport() = 0;
122 virtual bool getFloat32TextureSupport(bool *filtering, bool *renderable) = 0;
123 virtual bool getFloat16TextureSupport(bool *filtering, bool *renderable) = 0;
124 virtual bool getLuminanceTextureSupport() = 0;
125 virtual bool getLuminanceAlphaTextureSupport() = 0;
126 virtual bool getVertexTextureSupport() const = 0;
127 virtual bool getNonPower2TextureSupport() const = 0;
128 virtual bool getDepthTextureSupport() const = 0;
129 virtual bool getOcclusionQuerySupport() const = 0;
130 virtual bool getInstancingSupport() const = 0;
131 virtual bool getTextureFilterAnisotropySupport() const = 0;
132 virtual float getTextureMaxAnisotropy() const = 0;
133 virtual bool getShareHandleSupport() const = 0;
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000134
daniel@transgaming.com9549bea2012-11-28 20:57:23 +0000135 virtual int getMajorShaderModel() const = 0;
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000136 virtual float getMaxPointSize() const = 0;
137 virtual int getMaxTextureWidth() const = 0;
138 virtual int getMaxTextureHeight() const = 0;
139 virtual bool get32BitIndexSupport() const = 0;
140 virtual int getMinSwapInterval() const = 0;
141 virtual int getMaxSwapInterval() const = 0;
daniel@transgaming.com5f4c1362012-10-31 18:29:00 +0000142
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000143 virtual GLsizei getMaxSupportedSamples() const = 0;
daniel@transgaming.comb7833982012-10-31 18:31:46 +0000144
daniel@transgaming.coma9c71422012-11-28 20:58:45 +0000145 // Pixel operations
daniel@transgaming.com31b13e12012-11-28 19:34:30 +0000146 virtual bool copyToRenderTarget(TextureStorage2D *dest, TextureStorage2D *source) = 0;
147 virtual bool copyToRenderTarget(TextureStorageCubeMap *dest, TextureStorageCubeMap *source) = 0;
daniel@transgaming.com1d80eee2012-11-28 19:33:31 +0000148
daniel@transgaming.com38380882012-11-28 19:36:39 +0000149 virtual bool copyImage(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat,
150 GLint xoffset, GLint yoffset, TextureStorage2D *storage, GLint level) = 0;
151 virtual bool copyImage(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat,
152 GLint xoffset, GLint yoffset, TextureStorageCubeMap *storage, GLenum target, GLint level) = 0;
daniel@transgaming.comde8a7ff2012-11-28 19:34:13 +0000153
daniel@transgaming.com6c872172012-11-28 19:39:33 +0000154 virtual bool blitRect(gl::Framebuffer *readTarget, gl::Rectangle *readRect, gl::Framebuffer *drawTarget, gl::Rectangle *drawRect,
155 bool blitRenderTarget, bool blitDepthStencil) = 0;
156 virtual void readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type,
157 GLsizei outputPitch, bool packReverseRowOrder, GLint packAlignment, void* pixels) = 0;
158
daniel@transgaming.coma9c71422012-11-28 20:58:45 +0000159 // RenderTarget creation
daniel@transgaming.comf2423652012-11-28 20:53:50 +0000160 virtual RenderTarget *createRenderTarget(SwapChain *swapChain, bool depth) = 0;
161 virtual RenderTarget *createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth) = 0;
162
daniel@transgaming.coma9c71422012-11-28 20:58:45 +0000163 // Shader operations
daniel@transgaming.com55318902012-11-28 20:58:58 +0000164 virtual ShaderExecutable *loadExecutable(const DWORD *function, size_t length, GLenum type, void *data) = 0;
daniel@transgaming.coma9c71422012-11-28 20:58:45 +0000165 virtual ShaderExecutable *compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, GLenum type) = 0;
166
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000167 protected:
daniel@transgaming.comef21ab22012-10-31 17:52:47 +0000168 egl::Display *mDisplay;
daniel@transgaming.com4f0af572012-10-31 19:55:46 +0000169
170 private:
171 DISALLOW_COPY_AND_ASSIGN(Renderer);
172
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000173};
174
175}
176#endif // LIBGLESV2_RENDERER_RENDERER_H_