blob: adf6b9f29bbc5c39c6b253c5846f4227117a06f6 [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.com621ce052012-10-31 17:52:29 +000022const int versionWindowsVista = MAKEWORD(0x00, 0x06);
23const int versionWindows7 = MAKEWORD(0x01, 0x06);
24
25// Return the version of the operating system in a format suitable for ordering
26// comparison.
27inline int getComparableOSVersion()
28{
29 DWORD version = GetVersion();
30 int majorVersion = LOBYTE(LOWORD(version));
31 int minorVersion = HIBYTE(LOWORD(version));
32 return MAKEWORD(minorVersion, majorVersion);
33}
34
daniel@transgaming.comef21ab22012-10-31 17:52:47 +000035namespace egl
36{
37class Display;
38}
39
daniel@transgaming.com83e80ee2012-11-28 19:40:53 +000040namespace gl
41{
42class ProgramBinary;
daniel@transgaming.com67094ee2012-11-28 20:53:04 +000043class VertexAttribute;
daniel@transgaming.com91207b72012-11-28 20:56:43 +000044class Buffer;
45struct TranslatedIndexData;
daniel@transgaming.com83e80ee2012-11-28 19:40:53 +000046}
47
daniel@transgaming.com31b13e12012-11-28 19:34:30 +000048namespace rx
daniel@transgaming.com1d80eee2012-11-28 19:33:31 +000049{
50class TextureStorage2D;
51class TextureStorageCubeMap;
daniel@transgaming.comde8a7ff2012-11-28 19:34:13 +000052class Blit;
53
daniel@transgaming.com3281f972012-10-31 18:38:51 +000054struct ConfigDesc
55{
56 GLenum renderTargetFormat;
57 GLenum depthStencilFormat;
58 GLint multiSample;
59 bool fastConfig;
60};
61
daniel@transgaming.com621ce052012-10-31 17:52:29 +000062class Renderer
63{
64 public:
daniel@transgaming.com4f0af572012-10-31 19:55:46 +000065 explicit Renderer(egl::Display *display) : mDisplay(display) {};
daniel@transgaming.com2507f412012-10-31 18:46:48 +000066 virtual ~Renderer() {};
daniel@transgaming.com621ce052012-10-31 17:52:29 +000067
daniel@transgaming.com2507f412012-10-31 18:46:48 +000068 virtual EGLint initialize() = 0;
69 virtual bool resetDevice() = 0;
daniel@transgaming.com621ce052012-10-31 17:52:29 +000070
daniel@transgaming.com2507f412012-10-31 18:46:48 +000071 virtual int generateConfigs(ConfigDesc **configDescList) = 0;
72 virtual void deleteConfigs(ConfigDesc *configDescList) = 0;
daniel@transgaming.com3281f972012-10-31 18:38:51 +000073
daniel@transgaming.com2507f412012-10-31 18:46:48 +000074 virtual void sync(bool block) = 0;
daniel@transgaming.comef21ab22012-10-31 17:52:47 +000075
daniel@transgaming.comb9bb2792012-11-28 19:36:49 +000076 virtual SwapChain *createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) = 0;
77
daniel@transgaming.com2507f412012-10-31 18:46:48 +000078 virtual void setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &sampler) = 0;
79 virtual void setTexture(gl::SamplerType type, int index, gl::Texture *texture) = 0;
daniel@transgaming.com621ce052012-10-31 17:52:29 +000080
daniel@transgaming.com493d4f82012-11-28 19:35:45 +000081 virtual void setRasterizerState(const gl::RasterizerState &rasterState, unsigned int depthSize) = 0;
82 virtual void setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor,
83 unsigned int sampleMask) = 0;
daniel@transgaming.com08c331d2012-11-28 19:38:39 +000084 virtual void setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef,
85 int stencilBackRef, bool frontFaceCCW, unsigned int stencilSize) = 0;
daniel@transgaming.com493d4f82012-11-28 19:35:45 +000086
87 virtual void setScissorRectangle(const gl::Rectangle& scissor, unsigned int renderTargetWidth,
88 unsigned int renderTargetHeight) = 0;
daniel@transgaming.com83e80ee2012-11-28 19:40:53 +000089 virtual bool setViewport(const gl::Rectangle& viewport, float zNear, float zFar,
90 unsigned int renderTargetWidth, unsigned int renderTargetHeight,
91 gl::ProgramBinary *currentProgram, bool forceSetUniforms) = 0;
daniel@transgaming.com493d4f82012-11-28 19:35:45 +000092
daniel@transgaming.comae39ee22012-11-28 19:42:02 +000093 virtual bool applyRenderTarget(gl::Framebuffer *frameBuffer) = 0;
daniel@transgaming.com5fbf1772012-11-28 20:54:43 +000094 virtual void applyShaders(gl::ProgramBinary *programBinary) = 0;
daniel@transgaming.com91207b72012-11-28 20:56:43 +000095 virtual bool applyPrimitiveType(GLenum primitiveType, GLsizei elementCount) = 0;
96 virtual GLenum applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances) = 0;
97 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 +000098
daniel@transgaming.com91207b72012-11-28 20:56:43 +000099 virtual void drawArrays(GLenum mode, GLsizei count, GLsizei instances) = 0;
100 virtual void drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, gl::Buffer *elementArrayBuffer) = 0;
daniel@transgaming.com67094ee2012-11-28 20:53:04 +0000101
daniel@transgaming.com084a2572012-11-28 20:55:17 +0000102 virtual void clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) = 0;
daniel@transgaming.comd084c622012-11-28 19:36:05 +0000103
daniel@transgaming.comc43a6052012-11-28 19:41:51 +0000104 virtual void markAllStateDirty() = 0;
105
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000106 // lost device
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000107 virtual void markDeviceLost() = 0;
108 virtual bool isDeviceLost() = 0;
109 virtual bool testDeviceLost(bool notify) = 0;
110 virtual bool testDeviceResettable() = 0;
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000111
112 // Renderer capabilities
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000113 virtual DWORD getAdapterVendor() const = 0;
114 virtual const char *getAdapterDescription() const = 0;
115 virtual GUID getAdapterIdentifier() const = 0;
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000116
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000117 virtual bool getDXT1TextureSupport() = 0;
118 virtual bool getDXT3TextureSupport() = 0;
119 virtual bool getDXT5TextureSupport() = 0;
120 virtual bool getEventQuerySupport() = 0;
121 virtual bool getFloat32TextureSupport(bool *filtering, bool *renderable) = 0;
122 virtual bool getFloat16TextureSupport(bool *filtering, bool *renderable) = 0;
123 virtual bool getLuminanceTextureSupport() = 0;
124 virtual bool getLuminanceAlphaTextureSupport() = 0;
125 virtual bool getVertexTextureSupport() const = 0;
126 virtual bool getNonPower2TextureSupport() const = 0;
127 virtual bool getDepthTextureSupport() const = 0;
128 virtual bool getOcclusionQuerySupport() const = 0;
129 virtual bool getInstancingSupport() const = 0;
130 virtual bool getTextureFilterAnisotropySupport() const = 0;
131 virtual float getTextureMaxAnisotropy() const = 0;
132 virtual bool getShareHandleSupport() const = 0;
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000133
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000134 virtual bool getShaderModel3Support() const = 0;
135 virtual float getMaxPointSize() const = 0;
136 virtual int getMaxTextureWidth() const = 0;
137 virtual int getMaxTextureHeight() const = 0;
138 virtual bool get32BitIndexSupport() const = 0;
139 virtual int getMinSwapInterval() const = 0;
140 virtual int getMaxSwapInterval() const = 0;
daniel@transgaming.com5f4c1362012-10-31 18:29:00 +0000141
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000142 virtual GLsizei getMaxSupportedSamples() const = 0;
daniel@transgaming.comb7833982012-10-31 18:31:46 +0000143
daniel@transgaming.com31b13e12012-11-28 19:34:30 +0000144 virtual bool copyToRenderTarget(TextureStorage2D *dest, TextureStorage2D *source) = 0;
145 virtual bool copyToRenderTarget(TextureStorageCubeMap *dest, TextureStorageCubeMap *source) = 0;
daniel@transgaming.com1d80eee2012-11-28 19:33:31 +0000146
daniel@transgaming.com38380882012-11-28 19:36:39 +0000147 virtual bool copyImage(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat,
148 GLint xoffset, GLint yoffset, TextureStorage2D *storage, GLint level) = 0;
149 virtual bool copyImage(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat,
150 GLint xoffset, GLint yoffset, TextureStorageCubeMap *storage, GLenum target, GLint level) = 0;
daniel@transgaming.comde8a7ff2012-11-28 19:34:13 +0000151
daniel@transgaming.com6c872172012-11-28 19:39:33 +0000152 virtual bool blitRect(gl::Framebuffer *readTarget, gl::Rectangle *readRect, gl::Framebuffer *drawTarget, gl::Rectangle *drawRect,
153 bool blitRenderTarget, bool blitDepthStencil) = 0;
154 virtual void readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type,
155 GLsizei outputPitch, bool packReverseRowOrder, GLint packAlignment, void* pixels) = 0;
156
daniel@transgaming.comf2423652012-11-28 20:53:50 +0000157 virtual RenderTarget *createRenderTarget(SwapChain *swapChain, bool depth) = 0;
158 virtual RenderTarget *createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth) = 0;
159
daniel@transgaming.com2507f412012-10-31 18:46:48 +0000160 protected:
daniel@transgaming.comef21ab22012-10-31 17:52:47 +0000161 egl::Display *mDisplay;
daniel@transgaming.com4f0af572012-10-31 19:55:46 +0000162
163 private:
164 DISALLOW_COPY_AND_ASSIGN(Renderer);
165
daniel@transgaming.com621ce052012-10-31 17:52:29 +0000166};
167
168}
169#endif // LIBGLESV2_RENDERER_RENDERER_H_