daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1 | // |
| 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 | // Renderer11.cpp: Implements a back-end specific class for the D3D11 renderer. |
| 8 | |
| 9 | #include "common/debug.h" |
daniel@transgaming.com | 5503fd0 | 2012-11-28 19:38:57 +0000 | [diff] [blame] | 10 | #include "libGLESv2/main.h" |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 11 | #include "libGLESv2/utilities.h" |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 12 | #include "libGLESv2/mathutil.h" |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 13 | #include "libGLESv2/renderer/Renderer11.h" |
daniel@transgaming.com | b6b27bc | 2012-11-28 20:54:30 +0000 | [diff] [blame^] | 14 | #include "libGLESv2/renderer/RenderTarget11.h" |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 15 | #include "libGLESv2/renderer/renderer11_utils.h" |
daniel@transgaming.com | a60160b | 2012-11-28 19:41:15 +0000 | [diff] [blame] | 16 | #include "libGLESv2/renderer/SwapChain11.h" |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 17 | |
| 18 | #include "libEGL/Config.h" |
| 19 | #include "libEGL/Display.h" |
| 20 | |
| 21 | namespace rx |
| 22 | { |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 23 | static const DXGI_FORMAT RenderTargetFormats[] = |
| 24 | { |
| 25 | DXGI_FORMAT_R8G8B8A8_UNORM |
| 26 | }; |
| 27 | |
| 28 | static const DXGI_FORMAT DepthStencilFormats[] = |
| 29 | { |
| 30 | DXGI_FORMAT_D24_UNORM_S8_UINT |
| 31 | }; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 32 | |
| 33 | Renderer11::Renderer11(egl::Display *display, HDC hDc) : Renderer(display), mDc(hDc) |
| 34 | { |
| 35 | mD3d11Module = NULL; |
| 36 | mDxgiModule = NULL; |
| 37 | |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 38 | mDeviceLost = false; |
| 39 | |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 40 | mDevice = NULL; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 41 | mDeviceContext = NULL; |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 42 | mDxgiAdapter = NULL; |
| 43 | mDxgiFactory = NULL; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | Renderer11::~Renderer11() |
| 47 | { |
| 48 | releaseDeviceResources(); |
| 49 | |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 50 | if (mDxgiFactory) |
| 51 | { |
| 52 | mDxgiFactory->Release(); |
| 53 | mDxgiFactory = NULL; |
| 54 | } |
| 55 | |
| 56 | if (mDxgiAdapter) |
| 57 | { |
| 58 | mDxgiAdapter->Release(); |
| 59 | mDxgiAdapter = NULL; |
| 60 | } |
| 61 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 62 | if (mDeviceContext) |
| 63 | { |
| 64 | mDeviceContext->Release(); |
| 65 | mDeviceContext = NULL; |
| 66 | } |
| 67 | |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 68 | if (mDevice) |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 69 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 70 | mDevice->Release(); |
| 71 | mDevice = NULL; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | if (mD3d11Module) |
| 75 | { |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 76 | FreeLibrary(mD3d11Module); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 77 | mD3d11Module = NULL; |
| 78 | } |
| 79 | |
| 80 | if (mDxgiModule) |
| 81 | { |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 82 | FreeLibrary(mDxgiModule); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 83 | mDxgiModule = NULL; |
| 84 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 85 | } |
| 86 | |
daniel@transgaming.com | b64ed28 | 2012-11-28 20:54:02 +0000 | [diff] [blame] | 87 | Renderer11 *Renderer11::makeRenderer11(Renderer *renderer) |
| 88 | { |
| 89 | ASSERT(dynamic_cast<rx::Renderer11*>(renderer) != NULL); |
| 90 | return static_cast<rx::Renderer11*>(renderer); |
| 91 | } |
| 92 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 93 | EGLint Renderer11::initialize() |
| 94 | { |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 95 | mDxgiModule = LoadLibrary(TEXT("dxgi.dll")); |
| 96 | mD3d11Module = LoadLibrary(TEXT("d3d11.dll")); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 97 | |
| 98 | if (mD3d11Module == NULL || mDxgiModule == NULL) |
| 99 | { |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 100 | ERR("Could not load D3D11 or DXGI library - aborting!\n"); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 101 | return EGL_NOT_INITIALIZED; |
| 102 | } |
| 103 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 104 | PFN_D3D11_CREATE_DEVICE D3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)GetProcAddress(mD3d11Module, "D3D11CreateDevice"); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 105 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 106 | if (D3D11CreateDevice == NULL) |
| 107 | { |
| 108 | ERR("Could not retrieve D3D11CreateDevice address - aborting!\n"); |
| 109 | return EGL_NOT_INITIALIZED; |
| 110 | } |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 111 | |
| 112 | D3D_FEATURE_LEVEL featureLevel[] = |
| 113 | { |
| 114 | D3D_FEATURE_LEVEL_11_0, |
| 115 | D3D_FEATURE_LEVEL_10_1, |
| 116 | D3D_FEATURE_LEVEL_10_0, |
| 117 | }; |
| 118 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 119 | HRESULT result = D3D11CreateDevice(NULL, |
| 120 | D3D_DRIVER_TYPE_HARDWARE, |
| 121 | NULL, |
daniel@transgaming.com | a60160b | 2012-11-28 19:41:15 +0000 | [diff] [blame] | 122 | #if defined(_DEBUG) |
| 123 | D3D11_CREATE_DEVICE_DEBUG, |
| 124 | #else |
| 125 | 0, |
| 126 | #endif |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 127 | featureLevel, |
| 128 | sizeof(featureLevel)/sizeof(featureLevel[0]), |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 129 | D3D11_SDK_VERSION, |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 130 | &mDevice, |
| 131 | &mFeatureLevel, |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 132 | &mDeviceContext); |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 133 | |
| 134 | if (!mDevice || FAILED(result)) |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 135 | { |
| 136 | ERR("Could not create D3D11 device - aborting!\n"); |
| 137 | return EGL_NOT_INITIALIZED; // Cleanup done by destructor through glDestroyRenderer |
| 138 | } |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 139 | |
| 140 | IDXGIDevice *dxgiDevice = NULL; |
| 141 | result = mDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice); |
| 142 | |
| 143 | if (FAILED(result)) |
| 144 | { |
| 145 | ERR("Could not query DXGI device - aborting!\n"); |
| 146 | return EGL_NOT_INITIALIZED; |
| 147 | } |
| 148 | |
| 149 | result = dxgiDevice->GetParent(__uuidof(IDXGIAdapter), (void**)&mDxgiAdapter); |
| 150 | |
| 151 | if (FAILED(result)) |
| 152 | { |
| 153 | ERR("Could not retrieve DXGI adapter - aborting!\n"); |
| 154 | return EGL_NOT_INITIALIZED; |
| 155 | } |
| 156 | |
| 157 | dxgiDevice->Release(); |
| 158 | |
| 159 | result = mDxgiAdapter->GetParent(__uuidof(IDXGIFactory), (void**)&mDxgiFactory); |
| 160 | |
| 161 | if (!mDxgiFactory || FAILED(result)) |
| 162 | { |
| 163 | ERR("Could not create DXGI factory - aborting!\n"); |
| 164 | return EGL_NOT_INITIALIZED; |
| 165 | } |
| 166 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 167 | initializeDevice(); |
| 168 | |
| 169 | return EGL_SUCCESS; |
| 170 | } |
| 171 | |
| 172 | // do any one-time device initialization |
| 173 | // NOTE: this is also needed after a device lost/reset |
| 174 | // to reset the scene status and ensure the default states are reset. |
| 175 | void Renderer11::initializeDevice() |
| 176 | { |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 177 | mStateCache.initialize(mDevice); |
| 178 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 179 | markAllStateDirty(); |
| 180 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 181 | // Permanent non-default states |
| 182 | // TODO |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 183 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 184 | } |
| 185 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 186 | int Renderer11::generateConfigs(ConfigDesc **configDescList) |
| 187 | { |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 188 | unsigned int numRenderFormats = sizeof(RenderTargetFormats) / sizeof(RenderTargetFormats[0]); |
| 189 | unsigned int numDepthFormats = sizeof(DepthStencilFormats) / sizeof(DepthStencilFormats[0]); |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 190 | (*configDescList) = new ConfigDesc[numRenderFormats * numDepthFormats]; |
| 191 | int numConfigs = 0; |
| 192 | |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 193 | for (unsigned int formatIndex = 0; formatIndex < numRenderFormats; formatIndex++) |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 194 | { |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 195 | for (unsigned int depthStencilIndex = 0; depthStencilIndex < numDepthFormats; depthStencilIndex++) |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 196 | { |
| 197 | DXGI_FORMAT renderTargetFormat = RenderTargetFormats[formatIndex]; |
| 198 | |
| 199 | UINT formatSupport = 0; |
| 200 | HRESULT result = mDevice->CheckFormatSupport(renderTargetFormat, &formatSupport); |
| 201 | |
| 202 | if (SUCCEEDED(result) && (formatSupport & D3D11_FORMAT_SUPPORT_RENDER_TARGET)) |
| 203 | { |
| 204 | DXGI_FORMAT depthStencilFormat = DepthStencilFormats[depthStencilIndex]; |
| 205 | |
| 206 | UINT formatSupport = 0; |
| 207 | HRESULT result = mDevice->CheckFormatSupport(depthStencilFormat, &formatSupport); |
| 208 | |
| 209 | if (SUCCEEDED(result) && (formatSupport & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL)) |
| 210 | { |
| 211 | ConfigDesc newConfig; |
| 212 | newConfig.renderTargetFormat = d3d11_gl::ConvertBackBufferFormat(renderTargetFormat); |
| 213 | newConfig.depthStencilFormat = d3d11_gl::ConvertDepthStencilFormat(depthStencilFormat); |
| 214 | newConfig.multiSample = 0; // FIXME: enumerate multi-sampling |
| 215 | newConfig.fastConfig = true; // Assume all DX11 format conversions to be fast |
| 216 | |
| 217 | (*configDescList)[numConfigs++] = newConfig; |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | return numConfigs; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | void Renderer11::deleteConfigs(ConfigDesc *configDescList) |
| 227 | { |
| 228 | delete [] (configDescList); |
| 229 | } |
| 230 | |
| 231 | void Renderer11::startScene() |
| 232 | { |
| 233 | // TODO: nop in d3d11? |
| 234 | } |
| 235 | |
| 236 | void Renderer11::endScene() |
| 237 | { |
| 238 | // TODO: nop in d3d11? |
| 239 | } |
| 240 | |
| 241 | void Renderer11::sync(bool block) |
| 242 | { |
| 243 | // TODO |
| 244 | UNIMPLEMENTED(); |
| 245 | } |
| 246 | |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 247 | SwapChain *Renderer11::createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) |
| 248 | { |
daniel@transgaming.com | a60160b | 2012-11-28 19:41:15 +0000 | [diff] [blame] | 249 | return new rx::SwapChain11(this, window, shareHandle, backBufferFormat, depthBufferFormat); |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 250 | } |
| 251 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 252 | void Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState) |
| 253 | { |
| 254 | // TODO |
| 255 | UNIMPLEMENTED(); |
| 256 | } |
| 257 | |
| 258 | void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *texture) |
| 259 | { |
| 260 | // TODO |
| 261 | UNIMPLEMENTED(); |
| 262 | } |
| 263 | |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 264 | void Renderer11::setRasterizerState(const gl::RasterizerState &rasterState, unsigned int depthSize) |
| 265 | { |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 266 | if (mForceSetRasterState || |
| 267 | memcmp(&rasterState, &mCurRasterState, sizeof(gl::RasterizerState)) != 0 || |
| 268 | depthSize != mCurDepthSize) |
| 269 | { |
| 270 | ID3D11RasterizerState *dxRasterState = mStateCache.getRasterizerState(rasterState, depthSize); |
| 271 | if (!dxRasterState) |
| 272 | { |
| 273 | ERR("NULL blend state returned by RenderStateCache::getRasterizerState, setting the " |
| 274 | "rasterizer state."); |
| 275 | } |
| 276 | |
| 277 | mDeviceContext->RSSetState(dxRasterState); |
| 278 | |
| 279 | if (dxRasterState) |
| 280 | { |
| 281 | dxRasterState->Release(); |
| 282 | } |
| 283 | mCurRasterState = rasterState; |
| 284 | mCurDepthSize = depthSize; |
| 285 | } |
| 286 | |
| 287 | mForceSetRasterState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | void Renderer11::setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor, |
| 291 | unsigned int sampleMask) |
| 292 | { |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 293 | if (mForceSetBlendState || |
| 294 | memcmp(&blendState, &mCurBlendState, sizeof(gl::BlendState)) != 0 || |
| 295 | memcmp(&blendColor, &mCurBlendColor, sizeof(gl::Color)) != 0 || |
| 296 | sampleMask != mCurSampleMask) |
| 297 | { |
| 298 | ID3D11BlendState *dxBlendState = mStateCache.getBlendState(blendState); |
| 299 | if (!dxBlendState) |
| 300 | { |
| 301 | ERR("NULL blend state returned by RenderStateCache::getBlendState, setting the default " |
| 302 | "blend state."); |
| 303 | } |
| 304 | |
| 305 | const float blendColors[] = { blendColor.red, blendColor.green, blendColor.blue, blendColor.alpha }; |
| 306 | mDeviceContext->OMSetBlendState(dxBlendState, blendColors, sampleMask); |
| 307 | |
| 308 | if (dxBlendState) |
| 309 | { |
| 310 | dxBlendState->Release(); |
| 311 | } |
| 312 | mCurBlendState = blendState; |
| 313 | mCurBlendColor = blendColor; |
| 314 | mCurSampleMask = sampleMask; |
| 315 | } |
| 316 | |
| 317 | mForceSetBlendState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 318 | } |
| 319 | |
daniel@transgaming.com | 08c331d | 2012-11-28 19:38:39 +0000 | [diff] [blame] | 320 | void Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef, |
| 321 | int stencilBackRef, bool frontFaceCCW, unsigned int stencilSize) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 322 | { |
daniel@transgaming.com | 5503fd0 | 2012-11-28 19:38:57 +0000 | [diff] [blame] | 323 | if (mForceSetDepthStencilState || |
| 324 | memcmp(&depthStencilState, &mCurDepthStencilState, sizeof(gl::DepthStencilState)) != 0 || |
| 325 | stencilRef != mCurStencilRef || stencilBackRef != mCurStencilBackRef) |
| 326 | { |
| 327 | if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask || |
| 328 | stencilRef != stencilBackRef || |
| 329 | depthStencilState.stencilMask != depthStencilState.stencilBackMask) |
| 330 | { |
| 331 | ERR("Separate front/back stencil writemasks, reference values, or stencil mask values are " |
| 332 | "invalid under WebGL."); |
| 333 | return error(GL_INVALID_OPERATION); |
| 334 | } |
| 335 | |
| 336 | ID3D11DepthStencilState *dxDepthStencilState = mStateCache.getDepthStencilState(depthStencilState); |
| 337 | if (!dxDepthStencilState) |
| 338 | { |
| 339 | ERR("NULL depth stencil state returned by RenderStateCache::getDepthStencilState, " |
| 340 | "setting the default depth stencil state."); |
| 341 | } |
| 342 | |
| 343 | mDeviceContext->OMSetDepthStencilState(dxDepthStencilState, static_cast<UINT>(stencilRef)); |
| 344 | |
| 345 | if (dxDepthStencilState) |
| 346 | { |
| 347 | dxDepthStencilState->Release(); |
| 348 | } |
| 349 | mCurDepthStencilState = depthStencilState; |
| 350 | mCurStencilRef = stencilRef; |
| 351 | mCurStencilBackRef = stencilBackRef; |
| 352 | } |
| 353 | |
| 354 | mForceSetDepthStencilState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | void Renderer11::setScissorRectangle(const gl::Rectangle& scissor, unsigned int renderTargetWidth, |
| 358 | unsigned int renderTargetHeight) |
| 359 | { |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 360 | if (mForceSetScissor || |
| 361 | renderTargetWidth != mCurRenderTargetWidth || |
| 362 | renderTargetHeight != mCurRenderTargetHeight || |
| 363 | memcmp(&scissor, &mCurScissor, sizeof(gl::Rectangle)) != 0) |
| 364 | { |
| 365 | D3D11_RECT rect; |
| 366 | rect.left = gl::clamp(scissor.x, 0, static_cast<int>(renderTargetWidth)); |
daniel@transgaming.com | 1dd557a | 2012-11-28 19:44:00 +0000 | [diff] [blame] | 367 | rect.top = gl::clamp(scissor.y, 0, static_cast<int>(renderTargetHeight)); |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 368 | rect.right = gl::clamp(scissor.x + scissor.width, 0, static_cast<int>(renderTargetWidth)); |
daniel@transgaming.com | 1dd557a | 2012-11-28 19:44:00 +0000 | [diff] [blame] | 369 | rect.bottom = gl::clamp(scissor.y + scissor.height, 0, static_cast<int>(renderTargetHeight)); |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 370 | |
| 371 | mDeviceContext->RSSetScissorRects(1, &rect); |
| 372 | |
| 373 | mCurScissor = scissor; |
| 374 | mCurRenderTargetWidth = renderTargetWidth; |
| 375 | mCurRenderTargetHeight = renderTargetHeight; |
| 376 | } |
| 377 | |
| 378 | mForceSetScissor = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 379 | } |
| 380 | |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 381 | bool Renderer11::setViewport(const gl::Rectangle& viewport, float zNear, float zFar, |
| 382 | unsigned int renderTargetWidth, unsigned int renderTargetHeight, |
| 383 | gl::ProgramBinary *currentProgram, bool forceSetUniforms) |
| 384 | { |
| 385 | // TODO |
| 386 | UNIMPLEMENTED(); |
| 387 | return true; |
| 388 | } |
| 389 | |
daniel@transgaming.com | ae39ee2 | 2012-11-28 19:42:02 +0000 | [diff] [blame] | 390 | bool Renderer11::applyRenderTarget(gl::Framebuffer *frameBuffer) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 391 | { |
| 392 | // TODO |
| 393 | UNIMPLEMENTED(); |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 394 | |
| 395 | mForceSetScissor = true; |
daniel@transgaming.com | ae39ee2 | 2012-11-28 19:42:02 +0000 | [diff] [blame] | 396 | |
| 397 | return true; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 398 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 399 | |
daniel@transgaming.com | def9f0f | 2012-11-28 20:53:20 +0000 | [diff] [blame] | 400 | GLenum Renderer11::applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances, GLsizei *repeatDraw) |
| 401 | { |
| 402 | // TODO |
| 403 | UNIMPLEMENTED(); |
| 404 | |
| 405 | return GL_OUT_OF_MEMORY; |
| 406 | } |
| 407 | |
daniel@transgaming.com | d084c62 | 2012-11-28 19:36:05 +0000 | [diff] [blame] | 408 | void Renderer11::clear(GLbitfield mask, const gl::Color &colorClear, float depthClear, int stencilClear, |
| 409 | gl::Framebuffer *frameBuffer) |
| 410 | { |
| 411 | // TODO |
| 412 | UNIMPLEMENTED(); |
| 413 | } |
| 414 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 415 | void Renderer11::markAllStateDirty() |
| 416 | { |
| 417 | mForceSetBlendState = true; |
| 418 | mForceSetRasterState = true; |
| 419 | mForceSetDepthStencilState = true; |
| 420 | mForceSetScissor = true; |
| 421 | } |
| 422 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 423 | void Renderer11::releaseDeviceResources() |
| 424 | { |
| 425 | // TODO |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 426 | // UNIMPLEMENTED(); |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 427 | mStateCache.clear(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | void Renderer11::markDeviceLost() |
| 431 | { |
| 432 | mDeviceLost = true; |
| 433 | } |
| 434 | |
| 435 | bool Renderer11::isDeviceLost() |
| 436 | { |
| 437 | return mDeviceLost; |
| 438 | } |
| 439 | |
| 440 | // set notify to true to broadcast a message to all contexts of the device loss |
| 441 | bool Renderer11::testDeviceLost(bool notify) |
| 442 | { |
| 443 | bool isLost = false; |
| 444 | |
| 445 | // TODO |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 446 | //UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 447 | |
| 448 | if (isLost) |
| 449 | { |
| 450 | // ensure we note the device loss -- |
| 451 | // we'll probably get this done again by markDeviceLost |
| 452 | // but best to remember it! |
| 453 | // Note that we don't want to clear the device loss status here |
| 454 | // -- this needs to be done by resetDevice |
| 455 | mDeviceLost = true; |
| 456 | if (notify) |
| 457 | { |
| 458 | mDisplay->notifyDeviceLost(); |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | return isLost; |
| 463 | } |
| 464 | |
| 465 | bool Renderer11::testDeviceResettable() |
| 466 | { |
| 467 | HRESULT status = D3D_OK; |
| 468 | |
| 469 | // TODO |
| 470 | UNIMPLEMENTED(); |
| 471 | |
| 472 | switch (status) |
| 473 | { |
| 474 | case D3DERR_DEVICENOTRESET: |
| 475 | case D3DERR_DEVICEHUNG: |
| 476 | return true; |
| 477 | default: |
| 478 | return false; |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | bool Renderer11::resetDevice() |
| 483 | { |
| 484 | releaseDeviceResources(); |
| 485 | |
| 486 | // TODO |
| 487 | UNIMPLEMENTED(); |
| 488 | |
| 489 | // reset device defaults |
| 490 | initializeDevice(); |
| 491 | mDeviceLost = false; |
| 492 | |
| 493 | return true; |
| 494 | } |
| 495 | |
| 496 | DWORD Renderer11::getAdapterVendor() const |
| 497 | { |
| 498 | // TODO |
| 499 | UNIMPLEMENTED(); |
| 500 | return 0; |
| 501 | } |
| 502 | |
| 503 | const char *Renderer11::getAdapterDescription() const |
| 504 | { |
| 505 | // TODO |
| 506 | UNIMPLEMENTED(); |
| 507 | return "UNIMPLEMENTED"; |
| 508 | } |
| 509 | |
| 510 | GUID Renderer11::getAdapterIdentifier() const |
| 511 | { |
| 512 | // TODO |
| 513 | UNIMPLEMENTED(); |
| 514 | GUID foo = {}; |
| 515 | return foo; |
| 516 | } |
| 517 | |
| 518 | bool Renderer11::getDXT1TextureSupport() |
| 519 | { |
| 520 | // TODO |
| 521 | UNIMPLEMENTED(); |
| 522 | return false; |
| 523 | } |
| 524 | |
| 525 | bool Renderer11::getDXT3TextureSupport() |
| 526 | { |
| 527 | // TODO |
| 528 | UNIMPLEMENTED(); |
| 529 | return false; |
| 530 | } |
| 531 | |
| 532 | bool Renderer11::getDXT5TextureSupport() |
| 533 | { |
| 534 | // TODO |
| 535 | UNIMPLEMENTED(); |
| 536 | return false; |
| 537 | } |
| 538 | |
| 539 | bool Renderer11::getDepthTextureSupport() const |
| 540 | { |
| 541 | // TODO |
| 542 | UNIMPLEMENTED(); |
| 543 | return false; |
| 544 | } |
| 545 | |
| 546 | bool Renderer11::getFloat32TextureSupport(bool *filtering, bool *renderable) |
| 547 | { |
| 548 | // TODO |
| 549 | UNIMPLEMENTED(); |
| 550 | |
| 551 | *filtering = false; |
| 552 | *renderable = false; |
| 553 | return false; |
| 554 | } |
| 555 | |
| 556 | bool Renderer11::getFloat16TextureSupport(bool *filtering, bool *renderable) |
| 557 | { |
| 558 | // TODO |
| 559 | UNIMPLEMENTED(); |
| 560 | |
| 561 | *filtering = false; |
| 562 | *renderable = false; |
| 563 | return false; |
| 564 | } |
| 565 | |
| 566 | bool Renderer11::getLuminanceTextureSupport() |
| 567 | { |
| 568 | // TODO |
| 569 | UNIMPLEMENTED(); |
| 570 | return false; |
| 571 | } |
| 572 | |
| 573 | bool Renderer11::getLuminanceAlphaTextureSupport() |
| 574 | { |
| 575 | // TODO |
| 576 | UNIMPLEMENTED(); |
| 577 | return false; |
| 578 | } |
| 579 | |
| 580 | bool Renderer11::getTextureFilterAnisotropySupport() const |
| 581 | { |
| 582 | // TODO |
| 583 | UNIMPLEMENTED(); |
| 584 | return false; |
| 585 | } |
| 586 | |
| 587 | float Renderer11::getTextureMaxAnisotropy() const |
| 588 | { |
| 589 | // TODO |
| 590 | UNIMPLEMENTED(); |
| 591 | return 1.0f; |
| 592 | } |
| 593 | |
| 594 | bool Renderer11::getEventQuerySupport() |
| 595 | { |
| 596 | // TODO |
| 597 | UNIMPLEMENTED(); |
| 598 | return false; |
| 599 | } |
| 600 | |
| 601 | bool Renderer11::getVertexTextureSupport() const |
| 602 | { |
| 603 | // TODO |
| 604 | UNIMPLEMENTED(); |
| 605 | return false; |
| 606 | } |
| 607 | |
| 608 | bool Renderer11::getNonPower2TextureSupport() const |
| 609 | { |
| 610 | // TODO |
| 611 | UNIMPLEMENTED(); |
| 612 | return false; |
| 613 | } |
| 614 | |
| 615 | bool Renderer11::getOcclusionQuerySupport() const |
| 616 | { |
| 617 | // TODO |
| 618 | UNIMPLEMENTED(); |
| 619 | return false; |
| 620 | } |
| 621 | |
| 622 | bool Renderer11::getInstancingSupport() const |
| 623 | { |
| 624 | // TODO |
| 625 | UNIMPLEMENTED(); |
| 626 | return false; |
| 627 | } |
| 628 | |
| 629 | bool Renderer11::getShareHandleSupport() const |
| 630 | { |
| 631 | // TODO |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 632 | //UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 633 | |
| 634 | // PIX doesn't seem to support using share handles, so disable them. |
| 635 | return false && !gl::perfActive(); |
| 636 | } |
| 637 | |
| 638 | bool Renderer11::getShaderModel3Support() const |
| 639 | { |
| 640 | // TODO |
| 641 | UNIMPLEMENTED(); |
| 642 | return true; |
| 643 | } |
| 644 | |
| 645 | float Renderer11::getMaxPointSize() const |
| 646 | { |
| 647 | // TODO |
| 648 | UNIMPLEMENTED(); |
| 649 | return 1.0f; |
| 650 | } |
| 651 | |
| 652 | int Renderer11::getMaxTextureWidth() const |
| 653 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 654 | switch (mFeatureLevel) |
| 655 | { |
| 656 | case D3D_FEATURE_LEVEL_11_0: return D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 16384 |
| 657 | case D3D_FEATURE_LEVEL_10_1: |
| 658 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 8192 |
| 659 | default: UNREACHABLE(); return 0; |
| 660 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | int Renderer11::getMaxTextureHeight() const |
| 664 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 665 | switch (mFeatureLevel) |
| 666 | { |
| 667 | case D3D_FEATURE_LEVEL_11_0: return D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 16384 |
| 668 | case D3D_FEATURE_LEVEL_10_1: |
| 669 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 8192 |
| 670 | default: UNREACHABLE(); return 0; |
| 671 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | bool Renderer11::get32BitIndexSupport() const |
| 675 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 676 | switch (mFeatureLevel) |
| 677 | { |
| 678 | case D3D_FEATURE_LEVEL_11_0: |
| 679 | case D3D_FEATURE_LEVEL_10_1: |
| 680 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_DRAWINDEXED_INDEX_COUNT_2_TO_EXP >= 32; // true |
| 681 | default: UNREACHABLE(); return false; |
| 682 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | int Renderer11::getMinSwapInterval() const |
| 686 | { |
daniel@transgaming.com | 8c7b1a9 | 2012-11-28 19:34:06 +0000 | [diff] [blame] | 687 | return 0; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | int Renderer11::getMaxSwapInterval() const |
| 691 | { |
daniel@transgaming.com | 8c7b1a9 | 2012-11-28 19:34:06 +0000 | [diff] [blame] | 692 | return 4; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | int Renderer11::getMaxSupportedSamples() const |
| 696 | { |
| 697 | // TODO |
| 698 | UNIMPLEMENTED(); |
| 699 | return 1; |
| 700 | } |
| 701 | |
daniel@transgaming.com | 31b13e1 | 2012-11-28 19:34:30 +0000 | [diff] [blame] | 702 | bool Renderer11::copyToRenderTarget(TextureStorage2D *dest, TextureStorage2D *source) |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 703 | { |
| 704 | // TODO |
| 705 | UNIMPLEMENTED(); |
| 706 | return false; |
| 707 | } |
| 708 | |
daniel@transgaming.com | 31b13e1 | 2012-11-28 19:34:30 +0000 | [diff] [blame] | 709 | bool Renderer11::copyToRenderTarget(TextureStorageCubeMap *dest, TextureStorageCubeMap *source) |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 710 | { |
| 711 | // TODO |
| 712 | UNIMPLEMENTED(); |
| 713 | return false; |
| 714 | } |
| 715 | |
daniel@transgaming.com | 3838088 | 2012-11-28 19:36:39 +0000 | [diff] [blame] | 716 | bool Renderer11::copyImage(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, |
| 717 | GLint xoffset, GLint yoffset, TextureStorage2D *storage, GLint level) |
| 718 | { |
| 719 | // TODO |
| 720 | UNIMPLEMENTED(); |
| 721 | return false; |
| 722 | } |
| 723 | |
| 724 | bool Renderer11::copyImage(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, |
| 725 | GLint xoffset, GLint yoffset, TextureStorageCubeMap *storage, GLenum target, GLint level) |
| 726 | { |
| 727 | // TODO |
| 728 | UNIMPLEMENTED(); |
| 729 | return false; |
| 730 | } |
| 731 | |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 732 | RenderTarget *Renderer11::createRenderTarget(SwapChain *swapChain, bool depth) |
| 733 | { |
daniel@transgaming.com | b6b27bc | 2012-11-28 20:54:30 +0000 | [diff] [blame^] | 734 | SwapChain11 *swapChain11 = SwapChain11::makeSwapChain11(swapChain); |
| 735 | RenderTarget11 *renderTarget = NULL; |
| 736 | if (depth) |
| 737 | { |
| 738 | renderTarget = new RenderTarget11(this, swapChain11->getDepthStencil(), swapChain11->getWidth(), swapChain11->getHeight()); |
| 739 | } |
| 740 | else |
| 741 | { |
| 742 | renderTarget = new RenderTarget11(this, swapChain11->getRenderTarget(), swapChain11->getWidth(), swapChain11->getHeight()); |
| 743 | } |
| 744 | return renderTarget; |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | RenderTarget *Renderer11::createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth) |
| 748 | { |
| 749 | // TODO |
| 750 | UNIMPLEMENTED(); |
| 751 | return NULL; |
| 752 | } |
| 753 | |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 754 | bool Renderer11::blitRect(gl::Framebuffer *readTarget, gl::Rectangle *readRect, gl::Framebuffer *drawTarget, gl::Rectangle *drawRect, |
| 755 | bool blitRenderTarget, bool blitDepthStencil) |
| 756 | { |
| 757 | // TODO |
| 758 | UNIMPLEMENTED(); |
| 759 | return false; |
| 760 | } |
| 761 | |
| 762 | void Renderer11::readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, |
| 763 | GLsizei outputPitch, bool packReverseRowOrder, GLint packAlignment, void* pixels) |
| 764 | { |
| 765 | // TODO |
| 766 | UNIMPLEMENTED(); |
| 767 | return; |
| 768 | } |
| 769 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 770 | } |