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 | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 13 | #include "libGLESv2/Program.h" |
| 14 | #include "libGLESv2/ProgramBinary.h" |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 15 | #include "libGLESv2/Framebuffer.h" |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 16 | #include "libGLESv2/renderer/Renderer11.h" |
daniel@transgaming.com | b6b27bc | 2012-11-28 20:54:30 +0000 | [diff] [blame] | 17 | #include "libGLESv2/renderer/RenderTarget11.h" |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 18 | #include "libGLESv2/renderer/renderer11_utils.h" |
daniel@transgaming.com | a60160b | 2012-11-28 19:41:15 +0000 | [diff] [blame] | 19 | #include "libGLESv2/renderer/SwapChain11.h" |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 20 | |
| 21 | #include "libEGL/Config.h" |
| 22 | #include "libEGL/Display.h" |
| 23 | |
| 24 | namespace rx |
| 25 | { |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 26 | static const DXGI_FORMAT RenderTargetFormats[] = |
| 27 | { |
| 28 | DXGI_FORMAT_R8G8B8A8_UNORM |
| 29 | }; |
| 30 | |
| 31 | static const DXGI_FORMAT DepthStencilFormats[] = |
| 32 | { |
| 33 | DXGI_FORMAT_D24_UNORM_S8_UINT |
| 34 | }; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 35 | |
| 36 | Renderer11::Renderer11(egl::Display *display, HDC hDc) : Renderer(display), mDc(hDc) |
| 37 | { |
| 38 | mD3d11Module = NULL; |
| 39 | mDxgiModule = NULL; |
| 40 | |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 41 | mDeviceLost = false; |
| 42 | |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 43 | mDevice = NULL; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 44 | mDeviceContext = NULL; |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 45 | mDxgiAdapter = NULL; |
| 46 | mDxgiFactory = NULL; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | Renderer11::~Renderer11() |
| 50 | { |
| 51 | releaseDeviceResources(); |
| 52 | |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 53 | if (mDxgiFactory) |
| 54 | { |
| 55 | mDxgiFactory->Release(); |
| 56 | mDxgiFactory = NULL; |
| 57 | } |
| 58 | |
| 59 | if (mDxgiAdapter) |
| 60 | { |
| 61 | mDxgiAdapter->Release(); |
| 62 | mDxgiAdapter = NULL; |
| 63 | } |
| 64 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 65 | if (mDeviceContext) |
| 66 | { |
| 67 | mDeviceContext->Release(); |
| 68 | mDeviceContext = NULL; |
| 69 | } |
| 70 | |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 71 | if (mDevice) |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 72 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 73 | mDevice->Release(); |
| 74 | mDevice = NULL; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | if (mD3d11Module) |
| 78 | { |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 79 | FreeLibrary(mD3d11Module); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 80 | mD3d11Module = NULL; |
| 81 | } |
| 82 | |
| 83 | if (mDxgiModule) |
| 84 | { |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 85 | FreeLibrary(mDxgiModule); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 86 | mDxgiModule = NULL; |
| 87 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 88 | } |
| 89 | |
daniel@transgaming.com | b64ed28 | 2012-11-28 20:54:02 +0000 | [diff] [blame] | 90 | Renderer11 *Renderer11::makeRenderer11(Renderer *renderer) |
| 91 | { |
| 92 | ASSERT(dynamic_cast<rx::Renderer11*>(renderer) != NULL); |
| 93 | return static_cast<rx::Renderer11*>(renderer); |
| 94 | } |
| 95 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 96 | EGLint Renderer11::initialize() |
| 97 | { |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 98 | mDxgiModule = LoadLibrary(TEXT("dxgi.dll")); |
| 99 | mD3d11Module = LoadLibrary(TEXT("d3d11.dll")); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 100 | |
| 101 | if (mD3d11Module == NULL || mDxgiModule == NULL) |
| 102 | { |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 103 | ERR("Could not load D3D11 or DXGI library - aborting!\n"); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 104 | return EGL_NOT_INITIALIZED; |
| 105 | } |
| 106 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 107 | 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] | 108 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 109 | if (D3D11CreateDevice == NULL) |
| 110 | { |
| 111 | ERR("Could not retrieve D3D11CreateDevice address - aborting!\n"); |
| 112 | return EGL_NOT_INITIALIZED; |
| 113 | } |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 114 | |
| 115 | D3D_FEATURE_LEVEL featureLevel[] = |
| 116 | { |
| 117 | D3D_FEATURE_LEVEL_11_0, |
| 118 | D3D_FEATURE_LEVEL_10_1, |
| 119 | D3D_FEATURE_LEVEL_10_0, |
| 120 | }; |
| 121 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 122 | HRESULT result = D3D11CreateDevice(NULL, |
| 123 | D3D_DRIVER_TYPE_HARDWARE, |
| 124 | NULL, |
daniel@transgaming.com | a60160b | 2012-11-28 19:41:15 +0000 | [diff] [blame] | 125 | #if defined(_DEBUG) |
| 126 | D3D11_CREATE_DEVICE_DEBUG, |
| 127 | #else |
| 128 | 0, |
| 129 | #endif |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 130 | featureLevel, |
| 131 | sizeof(featureLevel)/sizeof(featureLevel[0]), |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 132 | D3D11_SDK_VERSION, |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 133 | &mDevice, |
| 134 | &mFeatureLevel, |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 135 | &mDeviceContext); |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 136 | |
| 137 | if (!mDevice || FAILED(result)) |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 138 | { |
| 139 | ERR("Could not create D3D11 device - aborting!\n"); |
| 140 | return EGL_NOT_INITIALIZED; // Cleanup done by destructor through glDestroyRenderer |
| 141 | } |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 142 | |
| 143 | IDXGIDevice *dxgiDevice = NULL; |
| 144 | result = mDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice); |
| 145 | |
| 146 | if (FAILED(result)) |
| 147 | { |
| 148 | ERR("Could not query DXGI device - aborting!\n"); |
| 149 | return EGL_NOT_INITIALIZED; |
| 150 | } |
| 151 | |
| 152 | result = dxgiDevice->GetParent(__uuidof(IDXGIAdapter), (void**)&mDxgiAdapter); |
| 153 | |
| 154 | if (FAILED(result)) |
| 155 | { |
| 156 | ERR("Could not retrieve DXGI adapter - aborting!\n"); |
| 157 | return EGL_NOT_INITIALIZED; |
| 158 | } |
| 159 | |
| 160 | dxgiDevice->Release(); |
| 161 | |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 162 | mDxgiAdapter->GetDesc(&mAdapterDescription); |
| 163 | memset(mDescription, 0, sizeof(mDescription)); |
| 164 | wcstombs(mDescription, mAdapterDescription.Description, sizeof(mDescription) - 1); |
| 165 | |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 166 | result = mDxgiAdapter->GetParent(__uuidof(IDXGIFactory), (void**)&mDxgiFactory); |
| 167 | |
| 168 | if (!mDxgiFactory || FAILED(result)) |
| 169 | { |
| 170 | ERR("Could not create DXGI factory - aborting!\n"); |
| 171 | return EGL_NOT_INITIALIZED; |
| 172 | } |
| 173 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 174 | initializeDevice(); |
| 175 | |
| 176 | return EGL_SUCCESS; |
| 177 | } |
| 178 | |
| 179 | // do any one-time device initialization |
| 180 | // NOTE: this is also needed after a device lost/reset |
| 181 | // to reset the scene status and ensure the default states are reset. |
| 182 | void Renderer11::initializeDevice() |
| 183 | { |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 184 | mStateCache.initialize(mDevice); |
| 185 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 186 | markAllStateDirty(); |
| 187 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 188 | // Permanent non-default states |
| 189 | // TODO |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 190 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 191 | } |
| 192 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 193 | int Renderer11::generateConfigs(ConfigDesc **configDescList) |
| 194 | { |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 195 | unsigned int numRenderFormats = sizeof(RenderTargetFormats) / sizeof(RenderTargetFormats[0]); |
| 196 | unsigned int numDepthFormats = sizeof(DepthStencilFormats) / sizeof(DepthStencilFormats[0]); |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 197 | (*configDescList) = new ConfigDesc[numRenderFormats * numDepthFormats]; |
| 198 | int numConfigs = 0; |
| 199 | |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 200 | for (unsigned int formatIndex = 0; formatIndex < numRenderFormats; formatIndex++) |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 201 | { |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 202 | for (unsigned int depthStencilIndex = 0; depthStencilIndex < numDepthFormats; depthStencilIndex++) |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 203 | { |
| 204 | DXGI_FORMAT renderTargetFormat = RenderTargetFormats[formatIndex]; |
| 205 | |
| 206 | UINT formatSupport = 0; |
| 207 | HRESULT result = mDevice->CheckFormatSupport(renderTargetFormat, &formatSupport); |
| 208 | |
| 209 | if (SUCCEEDED(result) && (formatSupport & D3D11_FORMAT_SUPPORT_RENDER_TARGET)) |
| 210 | { |
| 211 | DXGI_FORMAT depthStencilFormat = DepthStencilFormats[depthStencilIndex]; |
| 212 | |
| 213 | UINT formatSupport = 0; |
| 214 | HRESULT result = mDevice->CheckFormatSupport(depthStencilFormat, &formatSupport); |
| 215 | |
| 216 | if (SUCCEEDED(result) && (formatSupport & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL)) |
| 217 | { |
| 218 | ConfigDesc newConfig; |
| 219 | newConfig.renderTargetFormat = d3d11_gl::ConvertBackBufferFormat(renderTargetFormat); |
| 220 | newConfig.depthStencilFormat = d3d11_gl::ConvertDepthStencilFormat(depthStencilFormat); |
| 221 | newConfig.multiSample = 0; // FIXME: enumerate multi-sampling |
| 222 | newConfig.fastConfig = true; // Assume all DX11 format conversions to be fast |
| 223 | |
| 224 | (*configDescList)[numConfigs++] = newConfig; |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | return numConfigs; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | void Renderer11::deleteConfigs(ConfigDesc *configDescList) |
| 234 | { |
| 235 | delete [] (configDescList); |
| 236 | } |
| 237 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 238 | void Renderer11::sync(bool block) |
| 239 | { |
| 240 | // TODO |
| 241 | UNIMPLEMENTED(); |
| 242 | } |
| 243 | |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 244 | SwapChain *Renderer11::createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) |
| 245 | { |
daniel@transgaming.com | a60160b | 2012-11-28 19:41:15 +0000 | [diff] [blame] | 246 | return new rx::SwapChain11(this, window, shareHandle, backBufferFormat, depthBufferFormat); |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 247 | } |
| 248 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 249 | void Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState) |
| 250 | { |
| 251 | // TODO |
| 252 | UNIMPLEMENTED(); |
| 253 | } |
| 254 | |
| 255 | void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *texture) |
| 256 | { |
| 257 | // TODO |
| 258 | UNIMPLEMENTED(); |
| 259 | } |
| 260 | |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 261 | void Renderer11::setRasterizerState(const gl::RasterizerState &rasterState) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 262 | { |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 263 | if (mForceSetRasterState || memcmp(&rasterState, &mCurRasterState, sizeof(gl::RasterizerState)) != 0) |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 264 | { |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 265 | ID3D11RasterizerState *dxRasterState = mStateCache.getRasterizerState(rasterState, mCurDepthSize); |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 266 | if (!dxRasterState) |
| 267 | { |
| 268 | ERR("NULL blend state returned by RenderStateCache::getRasterizerState, setting the " |
| 269 | "rasterizer state."); |
| 270 | } |
| 271 | |
| 272 | mDeviceContext->RSSetState(dxRasterState); |
| 273 | |
| 274 | if (dxRasterState) |
| 275 | { |
| 276 | dxRasterState->Release(); |
| 277 | } |
| 278 | mCurRasterState = rasterState; |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | mForceSetRasterState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | void Renderer11::setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor, |
| 285 | unsigned int sampleMask) |
| 286 | { |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 287 | if (mForceSetBlendState || |
| 288 | memcmp(&blendState, &mCurBlendState, sizeof(gl::BlendState)) != 0 || |
| 289 | memcmp(&blendColor, &mCurBlendColor, sizeof(gl::Color)) != 0 || |
| 290 | sampleMask != mCurSampleMask) |
| 291 | { |
| 292 | ID3D11BlendState *dxBlendState = mStateCache.getBlendState(blendState); |
| 293 | if (!dxBlendState) |
| 294 | { |
| 295 | ERR("NULL blend state returned by RenderStateCache::getBlendState, setting the default " |
| 296 | "blend state."); |
| 297 | } |
| 298 | |
| 299 | const float blendColors[] = { blendColor.red, blendColor.green, blendColor.blue, blendColor.alpha }; |
| 300 | mDeviceContext->OMSetBlendState(dxBlendState, blendColors, sampleMask); |
| 301 | |
| 302 | if (dxBlendState) |
| 303 | { |
| 304 | dxBlendState->Release(); |
| 305 | } |
| 306 | mCurBlendState = blendState; |
| 307 | mCurBlendColor = blendColor; |
| 308 | mCurSampleMask = sampleMask; |
| 309 | } |
| 310 | |
| 311 | mForceSetBlendState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 312 | } |
| 313 | |
daniel@transgaming.com | 08c331d | 2012-11-28 19:38:39 +0000 | [diff] [blame] | 314 | void Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef, |
daniel@transgaming.com | 3a0ef48 | 2012-11-28 21:01:20 +0000 | [diff] [blame] | 315 | int stencilBackRef, bool frontFaceCCW) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 316 | { |
daniel@transgaming.com | 5503fd0 | 2012-11-28 19:38:57 +0000 | [diff] [blame] | 317 | if (mForceSetDepthStencilState || |
| 318 | memcmp(&depthStencilState, &mCurDepthStencilState, sizeof(gl::DepthStencilState)) != 0 || |
| 319 | stencilRef != mCurStencilRef || stencilBackRef != mCurStencilBackRef) |
| 320 | { |
| 321 | if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask || |
| 322 | stencilRef != stencilBackRef || |
| 323 | depthStencilState.stencilMask != depthStencilState.stencilBackMask) |
| 324 | { |
| 325 | ERR("Separate front/back stencil writemasks, reference values, or stencil mask values are " |
| 326 | "invalid under WebGL."); |
| 327 | return error(GL_INVALID_OPERATION); |
| 328 | } |
| 329 | |
| 330 | ID3D11DepthStencilState *dxDepthStencilState = mStateCache.getDepthStencilState(depthStencilState); |
| 331 | if (!dxDepthStencilState) |
| 332 | { |
| 333 | ERR("NULL depth stencil state returned by RenderStateCache::getDepthStencilState, " |
| 334 | "setting the default depth stencil state."); |
| 335 | } |
| 336 | |
| 337 | mDeviceContext->OMSetDepthStencilState(dxDepthStencilState, static_cast<UINT>(stencilRef)); |
| 338 | |
| 339 | if (dxDepthStencilState) |
| 340 | { |
| 341 | dxDepthStencilState->Release(); |
| 342 | } |
| 343 | mCurDepthStencilState = depthStencilState; |
| 344 | mCurStencilRef = stencilRef; |
| 345 | mCurStencilBackRef = stencilBackRef; |
| 346 | } |
| 347 | |
| 348 | mForceSetDepthStencilState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 349 | } |
| 350 | |
daniel@transgaming.com | 04f1b33 | 2012-11-28 21:00:40 +0000 | [diff] [blame] | 351 | void Renderer11::setScissorRectangle(const gl::Rectangle &scissor) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 352 | { |
daniel@transgaming.com | 04f1b33 | 2012-11-28 21:00:40 +0000 | [diff] [blame] | 353 | if (mForceSetScissor || memcmp(&scissor, &mCurScissor, sizeof(gl::Rectangle)) != 0) |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 354 | { |
| 355 | D3D11_RECT rect; |
daniel@transgaming.com | 04f1b33 | 2012-11-28 21:00:40 +0000 | [diff] [blame] | 356 | rect.left = gl::clamp(scissor.x, 0, static_cast<int>(mRenderTargetDesc.width)); |
| 357 | rect.top = gl::clamp(scissor.y, 0, static_cast<int>(mRenderTargetDesc.height)); |
| 358 | rect.right = gl::clamp(scissor.x + scissor.width, 0, static_cast<int>(mRenderTargetDesc.width)); |
| 359 | rect.bottom = gl::clamp(scissor.y + scissor.height, 0, static_cast<int>(mRenderTargetDesc.height)); |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 360 | |
| 361 | mDeviceContext->RSSetScissorRects(1, &rect); |
| 362 | |
| 363 | mCurScissor = scissor; |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | mForceSetScissor = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 367 | } |
| 368 | |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 369 | bool Renderer11::setViewport(const gl::Rectangle &viewport, float zNear, float zFar, bool ignoreViewport, |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 370 | gl::ProgramBinary *currentProgram, bool forceSetUniforms) |
| 371 | { |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 372 | gl::Rectangle actualViewport = viewport; |
| 373 | float actualZNear = gl::clamp01(zNear); |
| 374 | float actualZFar = gl::clamp01(zFar); |
| 375 | if (ignoreViewport) |
| 376 | { |
| 377 | actualViewport.x = 0; |
| 378 | actualViewport.y = 0; |
| 379 | actualViewport.width = mRenderTargetDesc.width; |
| 380 | actualViewport.height = mRenderTargetDesc.height; |
| 381 | actualZNear = 0.0f; |
| 382 | actualZFar = 1.0f; |
| 383 | } |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 384 | |
| 385 | D3D11_VIEWPORT dxViewport; |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 386 | dxViewport.TopLeftX = gl::clamp(actualViewport.x, 0, static_cast<int>(mRenderTargetDesc.width)); |
| 387 | dxViewport.TopLeftY = gl::clamp(actualViewport.y, 0, static_cast<int>(mRenderTargetDesc.height)); |
| 388 | dxViewport.Width = gl::clamp(actualViewport.width, 0, static_cast<int>(mRenderTargetDesc.width) - static_cast<int>(dxViewport.TopLeftX)); |
| 389 | dxViewport.Height = gl::clamp(actualViewport.height, 0, static_cast<int>(mRenderTargetDesc.height) - static_cast<int>(dxViewport.TopLeftY)); |
| 390 | dxViewport.MinDepth = actualZNear; |
| 391 | dxViewport.MaxDepth = actualZFar; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 392 | |
| 393 | if (dxViewport.Width <= 0 || dxViewport.Height <= 0) |
| 394 | { |
| 395 | return false; // Nothing to render |
| 396 | } |
| 397 | |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 398 | bool viewportChanged = mForceSetViewport || memcmp(&actualViewport, &mCurViewport, sizeof(gl::Rectangle)) != 0 || |
| 399 | actualZNear != mCurNear || actualZFar != mCurFar; |
| 400 | |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 401 | if (viewportChanged) |
| 402 | { |
| 403 | mDeviceContext->RSSetViewports(1, &dxViewport); |
| 404 | |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 405 | mCurViewport = actualViewport; |
| 406 | mCurNear = actualZNear; |
| 407 | mCurFar = actualZFar; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | if (currentProgram && (viewportChanged || forceSetUniforms)) |
| 411 | { |
| 412 | GLint halfPixelSize = currentProgram->getDxHalfPixelSizeLocation(); |
| 413 | GLfloat xy[2] = { 0.0f, 0.0f }; |
| 414 | currentProgram->setUniform2fv(halfPixelSize, 1, xy); |
| 415 | |
| 416 | // These values are used for computing gl_FragCoord in Program::linkVaryings(). |
| 417 | GLint coord = currentProgram->getDxCoordLocation(); |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 418 | GLfloat whxy[4] = { actualViewport.width * 0.5f, |
| 419 | actualViewport.height * 0.5f, |
| 420 | actualViewport.x + (actualViewport.width * 0.5f), |
| 421 | actualViewport.y + (actualViewport.height * 0.5f) }; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 422 | currentProgram->setUniform4fv(coord, 1, whxy); |
| 423 | |
| 424 | GLint depth = currentProgram->getDxDepthLocation(); |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 425 | GLfloat dz[2] = { (actualZFar - actualZNear) * 0.5f, (actualZNear + actualZFar) * 0.5f }; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 426 | currentProgram->setUniform2fv(depth, 1, dz); |
| 427 | |
| 428 | GLint depthRange = currentProgram->getDxDepthRangeLocation(); |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 429 | GLfloat nearFarDiff[3] = { actualZNear, actualZFar, actualZFar - actualZNear }; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 430 | currentProgram->setUniform3fv(depthRange, 1, nearFarDiff); |
| 431 | } |
| 432 | |
| 433 | mForceSetViewport = false; |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 434 | return true; |
| 435 | } |
| 436 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 437 | bool Renderer11::applyPrimitiveType(GLenum mode, GLsizei count) |
| 438 | { |
| 439 | // TODO |
| 440 | UNIMPLEMENTED(); |
| 441 | |
| 442 | return false; |
| 443 | } |
| 444 | |
| 445 | bool Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 446 | { |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 447 | // Get the color render buffer and serial |
| 448 | gl::Renderbuffer *renderbufferObject = NULL; |
| 449 | unsigned int renderTargetSerial = 0; |
| 450 | if (framebuffer->getColorbufferType() != GL_NONE) |
| 451 | { |
| 452 | renderbufferObject = framebuffer->getColorbuffer(); |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 453 | |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 454 | if (!renderbufferObject) |
| 455 | { |
| 456 | ERR("render target pointer unexpectedly null."); |
daniel@transgaming.com | e9c71b4 | 2012-11-28 21:02:23 +0000 | [diff] [blame] | 457 | return false; |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | renderTargetSerial = renderbufferObject->getSerial(); |
| 461 | } |
| 462 | |
| 463 | // Get the depth stencil render buffer and serials |
| 464 | gl::Renderbuffer *depthStencil = NULL; |
| 465 | unsigned int depthbufferSerial = 0; |
| 466 | unsigned int stencilbufferSerial = 0; |
| 467 | if (framebuffer->getDepthbufferType() != GL_NONE) |
| 468 | { |
| 469 | depthStencil = framebuffer->getDepthbuffer(); |
| 470 | if (!depthStencil) |
| 471 | { |
| 472 | ERR("Depth stencil pointer unexpectedly null."); |
| 473 | return false; |
| 474 | } |
| 475 | |
| 476 | depthbufferSerial = depthStencil->getSerial(); |
| 477 | } |
| 478 | else if (framebuffer->getStencilbufferType() != GL_NONE) |
| 479 | { |
| 480 | depthStencil = framebuffer->getStencilbuffer(); |
| 481 | if (!depthStencil) |
| 482 | { |
| 483 | ERR("Depth stencil pointer unexpectedly null."); |
| 484 | return false; |
| 485 | } |
| 486 | |
| 487 | stencilbufferSerial = depthStencil->getSerial(); |
| 488 | } |
| 489 | |
| 490 | // Extract the render target dimensions and view |
| 491 | unsigned int renderTargetWidth = 0; |
| 492 | unsigned int renderTargetHeight = 0; |
| 493 | GLenum renderTargetFormat = 0; |
| 494 | ID3D11RenderTargetView* framebufferRTV = NULL; |
| 495 | if (renderbufferObject) |
| 496 | { |
| 497 | RenderTarget11 *renderTarget = RenderTarget11::makeRenderTarget11(renderbufferObject->getRenderTarget()); |
| 498 | if (!renderTarget) |
| 499 | { |
| 500 | ERR("render target pointer unexpectedly null."); |
| 501 | return false; |
| 502 | } |
| 503 | |
| 504 | framebufferRTV = renderTarget->getRenderTargetView(); |
| 505 | if (!framebufferRTV) |
| 506 | { |
| 507 | ERR("render target view pointer unexpectedly null."); |
| 508 | return false; |
| 509 | } |
| 510 | |
| 511 | renderTargetWidth = renderbufferObject->getWidth(); |
| 512 | renderTargetHeight = renderbufferObject->getHeight(); |
| 513 | renderTargetFormat = renderbufferObject->getActualFormat(); |
| 514 | } |
| 515 | |
| 516 | // Extract the depth stencil sizes and view |
| 517 | unsigned int depthSize = 0; |
| 518 | unsigned int stencilSize = 0; |
| 519 | ID3D11DepthStencilView* framebufferDSV = NULL; |
| 520 | if (depthStencil) |
| 521 | { |
| 522 | RenderTarget11 *depthStencilRenderTarget = RenderTarget11::makeRenderTarget11(depthStencil->getDepthStencil()); |
| 523 | if (!depthStencilRenderTarget) |
| 524 | { |
| 525 | ERR("render target pointer unexpectedly null."); |
| 526 | if (framebufferRTV) |
| 527 | { |
| 528 | framebufferRTV->Release(); |
| 529 | } |
| 530 | return false; |
| 531 | } |
| 532 | |
| 533 | framebufferDSV = depthStencilRenderTarget->getDepthStencilView(); |
| 534 | if (!framebufferDSV) |
| 535 | { |
| 536 | ERR("depth stencil view pointer unexpectedly null."); |
| 537 | if (framebufferRTV) |
| 538 | { |
| 539 | framebufferRTV->Release(); |
| 540 | } |
| 541 | return false; |
| 542 | } |
| 543 | |
| 544 | // If there is no render buffer, the width, height and format values come from |
| 545 | // the depth stencil |
| 546 | if (!renderbufferObject) |
| 547 | { |
| 548 | renderTargetWidth = depthStencil->getWidth(); |
| 549 | renderTargetHeight = depthStencil->getHeight(); |
| 550 | renderTargetFormat = depthStencil->getActualFormat(); |
| 551 | } |
| 552 | |
| 553 | depthSize = depthStencil->getDepthSize(); |
| 554 | stencilSize = depthStencil->getStencilSize(); |
| 555 | } |
| 556 | |
| 557 | // Apply the render target and depth stencil |
| 558 | if (!mRenderTargetDescInitialized || !mDepthStencilInitialized || |
| 559 | renderTargetSerial != mAppliedRenderTargetSerial || |
| 560 | depthbufferSerial != mAppliedDepthbufferSerial || |
| 561 | stencilbufferSerial != mAppliedStencilbufferSerial) |
| 562 | { |
| 563 | mDeviceContext->OMSetRenderTargets(1, &framebufferRTV, framebufferDSV); |
| 564 | |
| 565 | mRenderTargetDesc.width = renderTargetWidth; |
| 566 | mRenderTargetDesc.height = renderTargetHeight; |
| 567 | mRenderTargetDesc.format = renderTargetFormat; |
| 568 | mForceSetViewport = true; // TODO: It may not be required to clamp the viewport in D3D11 |
| 569 | mForceSetScissor = true; // TODO: It may not be required to clamp the scissor in D3D11 |
| 570 | |
| 571 | if (!mDepthStencilInitialized || depthSize != mCurDepthSize) |
| 572 | { |
| 573 | mCurDepthSize = depthSize; |
| 574 | mForceSetRasterState = true; |
| 575 | } |
| 576 | |
| 577 | mCurStencilSize = stencilSize; |
| 578 | |
| 579 | mAppliedRenderTargetSerial = renderTargetSerial; |
| 580 | mAppliedDepthbufferSerial = depthbufferSerial; |
| 581 | mAppliedStencilbufferSerial = stencilbufferSerial; |
| 582 | mRenderTargetDescInitialized = true; |
| 583 | mDepthStencilInitialized = true; |
| 584 | } |
| 585 | |
| 586 | if (framebufferRTV) |
| 587 | { |
| 588 | framebufferRTV->Release(); |
| 589 | } |
| 590 | if (framebufferDSV) |
| 591 | { |
| 592 | framebufferDSV->Release(); |
| 593 | } |
daniel@transgaming.com | ae39ee2 | 2012-11-28 19:42:02 +0000 | [diff] [blame] | 594 | |
| 595 | return true; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 596 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 597 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 598 | GLenum Renderer11::applyVertexBuffer(gl::ProgramBinary *programBinary, gl::VertexAttribute vertexAttributes[], GLint first, GLsizei count, GLsizei instances) |
daniel@transgaming.com | def9f0f | 2012-11-28 20:53:20 +0000 | [diff] [blame] | 599 | { |
| 600 | // TODO |
| 601 | UNIMPLEMENTED(); |
| 602 | |
| 603 | return GL_OUT_OF_MEMORY; |
| 604 | } |
| 605 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 606 | GLenum Renderer11::applyIndexBuffer(const GLvoid *indices, gl::Buffer *elementArrayBuffer, GLsizei count, GLenum mode, GLenum type, gl::TranslatedIndexData *indexInfo) |
| 607 | { |
| 608 | // TODO |
| 609 | UNIMPLEMENTED(); |
| 610 | |
| 611 | return GL_OUT_OF_MEMORY; |
| 612 | } |
| 613 | |
| 614 | void Renderer11::drawArrays(GLenum mode, GLsizei count, GLsizei instances) |
| 615 | { |
| 616 | // TODO |
| 617 | UNIMPLEMENTED(); |
| 618 | } |
| 619 | |
daniel@transgaming.com | 97400dd | 2012-11-28 20:57:00 +0000 | [diff] [blame] | 620 | void Renderer11::drawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, gl::Buffer *elementArrayBuffer, const gl::TranslatedIndexData &indexInfo) |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 621 | { |
| 622 | // TODO |
| 623 | UNIMPLEMENTED(); |
| 624 | } |
| 625 | |
daniel@transgaming.com | 5fbf177 | 2012-11-28 20:54:43 +0000 | [diff] [blame] | 626 | void Renderer11::applyShaders(gl::ProgramBinary *programBinary) |
| 627 | { |
| 628 | // TODO |
| 629 | UNIMPLEMENTED(); |
| 630 | } |
| 631 | |
daniel@transgaming.com | 084a257 | 2012-11-28 20:55:17 +0000 | [diff] [blame] | 632 | void Renderer11::clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) |
daniel@transgaming.com | d084c62 | 2012-11-28 19:36:05 +0000 | [diff] [blame] | 633 | { |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame^] | 634 | if (clearParams.mask & GL_COLOR_BUFFER_BIT) |
| 635 | { |
| 636 | gl::Renderbuffer *renderbufferObject = frameBuffer->getColorbuffer(); |
| 637 | if (renderbufferObject) |
| 638 | { |
| 639 | RenderTarget11 *renderTarget = RenderTarget11::makeRenderTarget11(renderbufferObject->getRenderTarget()); |
| 640 | if (!renderTarget) |
| 641 | { |
| 642 | ERR("render target pointer unexpectedly null."); |
| 643 | return; |
| 644 | } |
| 645 | |
| 646 | ID3D11RenderTargetView *framebufferRTV = renderTarget->getRenderTargetView(); |
| 647 | if (!framebufferRTV) |
| 648 | { |
| 649 | ERR("render target view pointer unexpectedly null."); |
| 650 | return; |
| 651 | } |
| 652 | |
| 653 | if (mCurScissor.x > 0 || mCurScissor.y > 0 || |
| 654 | mCurScissor.x + mCurScissor.width < renderTarget->getWidth() || |
| 655 | mCurScissor.y + mCurScissor.height < renderTarget->getHeight()) |
| 656 | { |
| 657 | // TODO: clearing of subregion of render target |
| 658 | UNIMPLEMENTED(); |
| 659 | } |
| 660 | |
| 661 | bool alphaUnmasked = (gl::GetAlphaSize(mRenderTargetDesc.format) == 0) || clearParams.colorMaskAlpha; |
| 662 | const bool needMaskedColorClear = (clearParams.mask & GL_COLOR_BUFFER_BIT) && |
| 663 | !(clearParams.colorMaskRed && clearParams.colorMaskGreen && |
| 664 | clearParams.colorMaskBlue && alphaUnmasked); |
| 665 | |
| 666 | if (needMaskedColorClear) |
| 667 | { |
| 668 | // TODO: masked color clearing |
| 669 | UNIMPLEMENTED(); |
| 670 | } |
| 671 | else |
| 672 | { |
| 673 | const float clearValues[4] = { clearParams.colorClearValue.red, |
| 674 | clearParams.colorClearValue.green, |
| 675 | clearParams.colorClearValue.blue, |
| 676 | clearParams.colorClearValue.alpha }; |
| 677 | mDeviceContext->ClearRenderTargetView(framebufferRTV, clearValues); |
| 678 | } |
| 679 | |
| 680 | framebufferRTV->Release(); |
| 681 | } |
| 682 | } |
| 683 | if (clearParams.mask & GL_DEPTH_BUFFER_BIT || clearParams.mask & GL_STENCIL_BUFFER_BIT) |
| 684 | { |
| 685 | gl::Renderbuffer *renderbufferObject = frameBuffer->getDepthOrStencilbuffer(); |
| 686 | if (renderbufferObject) |
| 687 | { |
| 688 | RenderTarget11 *renderTarget = RenderTarget11::makeRenderTarget11(renderbufferObject->getRenderTarget()); |
| 689 | if (!renderTarget) |
| 690 | { |
| 691 | ERR("render target pointer unexpectedly null."); |
| 692 | return; |
| 693 | } |
| 694 | |
| 695 | ID3D11DepthStencilView *framebufferDSV = renderTarget->getDepthStencilView(); |
| 696 | if (!framebufferDSV) |
| 697 | { |
| 698 | ERR("depth stencil view pointer unexpectedly null."); |
| 699 | return; |
| 700 | } |
| 701 | |
| 702 | if (mCurScissor.x > 0 || mCurScissor.y > 0 || |
| 703 | mCurScissor.x + mCurScissor.width < renderTarget->getWidth() || |
| 704 | mCurScissor.y + mCurScissor.height < renderTarget->getHeight()) |
| 705 | { |
| 706 | // TODO: clearing of subregion of depth stencil view |
| 707 | UNIMPLEMENTED(); |
| 708 | } |
| 709 | |
| 710 | unsigned int stencilUnmasked = 0x0; |
| 711 | if ((clearParams.mask & GL_STENCIL_BUFFER_BIT) && frameBuffer->hasStencil()) |
| 712 | { |
| 713 | unsigned int stencilSize = gl::GetStencilSize(frameBuffer->getStencilbuffer()->getActualFormat()); |
| 714 | stencilUnmasked = (0x1 << stencilSize) - 1; |
| 715 | } |
| 716 | |
| 717 | const bool needMaskedStencilClear = (clearParams.mask & GL_STENCIL_BUFFER_BIT) && |
| 718 | (clearParams.stencilWriteMask & stencilUnmasked) != stencilUnmasked; |
| 719 | |
| 720 | if (needMaskedStencilClear) |
| 721 | { |
| 722 | // TODO: masked clearing of depth stencil |
| 723 | UNIMPLEMENTED(); |
| 724 | } |
| 725 | else |
| 726 | { |
| 727 | UINT clearFlags = 0; |
| 728 | if (clearParams.mask & GL_DEPTH_BUFFER_BIT) |
| 729 | { |
| 730 | clearFlags |= D3D11_CLEAR_DEPTH; |
| 731 | } |
| 732 | if (clearParams.mask & GL_STENCIL_BUFFER_BIT) |
| 733 | { |
| 734 | clearFlags |= D3D11_CLEAR_STENCIL; |
| 735 | } |
| 736 | |
| 737 | float depthClear = clearParams.depthClearValue; |
| 738 | UINT8 stencilClear = clearParams.stencilClearValue & 0x000000FF; |
| 739 | |
| 740 | mDeviceContext->ClearDepthStencilView(framebufferDSV, clearFlags, depthClear, stencilClear); |
| 741 | } |
| 742 | |
| 743 | framebufferDSV->Release(); |
| 744 | } |
| 745 | } |
daniel@transgaming.com | d084c62 | 2012-11-28 19:36:05 +0000 | [diff] [blame] | 746 | } |
| 747 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 748 | void Renderer11::markAllStateDirty() |
| 749 | { |
daniel@transgaming.com | 7b6b83e | 2012-11-28 21:00:30 +0000 | [diff] [blame] | 750 | mDepthStencilInitialized = false; |
| 751 | mRenderTargetDescInitialized = false; |
| 752 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 753 | mForceSetBlendState = true; |
| 754 | mForceSetRasterState = true; |
| 755 | mForceSetDepthStencilState = true; |
| 756 | mForceSetScissor = true; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 757 | mForceSetViewport = true; |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 758 | } |
| 759 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 760 | void Renderer11::releaseDeviceResources() |
| 761 | { |
| 762 | // TODO |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 763 | // UNIMPLEMENTED(); |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 764 | mStateCache.clear(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 765 | } |
| 766 | |
| 767 | void Renderer11::markDeviceLost() |
| 768 | { |
| 769 | mDeviceLost = true; |
| 770 | } |
| 771 | |
| 772 | bool Renderer11::isDeviceLost() |
| 773 | { |
| 774 | return mDeviceLost; |
| 775 | } |
| 776 | |
| 777 | // set notify to true to broadcast a message to all contexts of the device loss |
| 778 | bool Renderer11::testDeviceLost(bool notify) |
| 779 | { |
| 780 | bool isLost = false; |
| 781 | |
| 782 | // TODO |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 783 | //UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 784 | |
| 785 | if (isLost) |
| 786 | { |
| 787 | // ensure we note the device loss -- |
| 788 | // we'll probably get this done again by markDeviceLost |
| 789 | // but best to remember it! |
| 790 | // Note that we don't want to clear the device loss status here |
| 791 | // -- this needs to be done by resetDevice |
| 792 | mDeviceLost = true; |
| 793 | if (notify) |
| 794 | { |
| 795 | mDisplay->notifyDeviceLost(); |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | return isLost; |
| 800 | } |
| 801 | |
| 802 | bool Renderer11::testDeviceResettable() |
| 803 | { |
| 804 | HRESULT status = D3D_OK; |
| 805 | |
| 806 | // TODO |
| 807 | UNIMPLEMENTED(); |
| 808 | |
| 809 | switch (status) |
| 810 | { |
| 811 | case D3DERR_DEVICENOTRESET: |
| 812 | case D3DERR_DEVICEHUNG: |
| 813 | return true; |
| 814 | default: |
| 815 | return false; |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | bool Renderer11::resetDevice() |
| 820 | { |
| 821 | releaseDeviceResources(); |
| 822 | |
| 823 | // TODO |
| 824 | UNIMPLEMENTED(); |
| 825 | |
| 826 | // reset device defaults |
| 827 | initializeDevice(); |
| 828 | mDeviceLost = false; |
| 829 | |
| 830 | return true; |
| 831 | } |
| 832 | |
| 833 | DWORD Renderer11::getAdapterVendor() const |
| 834 | { |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 835 | return mAdapterDescription.VendorId; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | const char *Renderer11::getAdapterDescription() const |
| 839 | { |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 840 | return mDescription; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | GUID Renderer11::getAdapterIdentifier() const |
| 844 | { |
| 845 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 846 | // UNIMPLEMENTED(); |
| 847 | GUID foo = {0}; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 848 | return foo; |
| 849 | } |
| 850 | |
| 851 | bool Renderer11::getDXT1TextureSupport() |
| 852 | { |
| 853 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 854 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 855 | return false; |
| 856 | } |
| 857 | |
| 858 | bool Renderer11::getDXT3TextureSupport() |
| 859 | { |
| 860 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 861 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 862 | return false; |
| 863 | } |
| 864 | |
| 865 | bool Renderer11::getDXT5TextureSupport() |
| 866 | { |
| 867 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 868 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 869 | return false; |
| 870 | } |
| 871 | |
| 872 | bool Renderer11::getDepthTextureSupport() const |
| 873 | { |
| 874 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 875 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 876 | return false; |
| 877 | } |
| 878 | |
| 879 | bool Renderer11::getFloat32TextureSupport(bool *filtering, bool *renderable) |
| 880 | { |
| 881 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 882 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 883 | |
| 884 | *filtering = false; |
| 885 | *renderable = false; |
| 886 | return false; |
| 887 | } |
| 888 | |
| 889 | bool Renderer11::getFloat16TextureSupport(bool *filtering, bool *renderable) |
| 890 | { |
| 891 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 892 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 893 | |
| 894 | *filtering = false; |
| 895 | *renderable = false; |
| 896 | return false; |
| 897 | } |
| 898 | |
| 899 | bool Renderer11::getLuminanceTextureSupport() |
| 900 | { |
| 901 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 902 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 903 | return false; |
| 904 | } |
| 905 | |
| 906 | bool Renderer11::getLuminanceAlphaTextureSupport() |
| 907 | { |
| 908 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 909 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 910 | return false; |
| 911 | } |
| 912 | |
| 913 | bool Renderer11::getTextureFilterAnisotropySupport() const |
| 914 | { |
| 915 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 916 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 917 | return false; |
| 918 | } |
| 919 | |
| 920 | float Renderer11::getTextureMaxAnisotropy() const |
| 921 | { |
| 922 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 923 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 924 | return 1.0f; |
| 925 | } |
| 926 | |
| 927 | bool Renderer11::getEventQuerySupport() |
| 928 | { |
| 929 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 930 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 931 | return false; |
| 932 | } |
| 933 | |
| 934 | bool Renderer11::getVertexTextureSupport() const |
| 935 | { |
| 936 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 937 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 938 | return false; |
| 939 | } |
| 940 | |
| 941 | bool Renderer11::getNonPower2TextureSupport() const |
| 942 | { |
| 943 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 944 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 945 | return false; |
| 946 | } |
| 947 | |
| 948 | bool Renderer11::getOcclusionQuerySupport() const |
| 949 | { |
| 950 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 951 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 952 | return false; |
| 953 | } |
| 954 | |
| 955 | bool Renderer11::getInstancingSupport() const |
| 956 | { |
| 957 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 958 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 959 | return false; |
| 960 | } |
| 961 | |
| 962 | bool Renderer11::getShareHandleSupport() const |
| 963 | { |
| 964 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 965 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 966 | |
| 967 | // PIX doesn't seem to support using share handles, so disable them. |
| 968 | return false && !gl::perfActive(); |
| 969 | } |
| 970 | |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 971 | int Renderer11::getMajorShaderModel() const |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 972 | { |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 973 | switch (mFeatureLevel) |
| 974 | { |
| 975 | case D3D_FEATURE_LEVEL_11_0: return D3D11_SHADER_MAJOR_VERSION; // 5 |
| 976 | case D3D_FEATURE_LEVEL_10_1: |
| 977 | case D3D_FEATURE_LEVEL_10_0: return D3D10_SHADER_MAJOR_VERSION; // 4 |
| 978 | default: UNREACHABLE(); return 0; |
| 979 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | float Renderer11::getMaxPointSize() const |
| 983 | { |
| 984 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 985 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 986 | return 1.0f; |
| 987 | } |
| 988 | |
| 989 | int Renderer11::getMaxTextureWidth() const |
| 990 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 991 | switch (mFeatureLevel) |
| 992 | { |
| 993 | case D3D_FEATURE_LEVEL_11_0: return D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 16384 |
| 994 | case D3D_FEATURE_LEVEL_10_1: |
| 995 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 8192 |
| 996 | default: UNREACHABLE(); return 0; |
| 997 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | int Renderer11::getMaxTextureHeight() const |
| 1001 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 1002 | switch (mFeatureLevel) |
| 1003 | { |
| 1004 | case D3D_FEATURE_LEVEL_11_0: return D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 16384 |
| 1005 | case D3D_FEATURE_LEVEL_10_1: |
| 1006 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 8192 |
| 1007 | default: UNREACHABLE(); return 0; |
| 1008 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | bool Renderer11::get32BitIndexSupport() const |
| 1012 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 1013 | switch (mFeatureLevel) |
| 1014 | { |
| 1015 | case D3D_FEATURE_LEVEL_11_0: |
| 1016 | case D3D_FEATURE_LEVEL_10_1: |
| 1017 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_DRAWINDEXED_INDEX_COUNT_2_TO_EXP >= 32; // true |
| 1018 | default: UNREACHABLE(); return false; |
| 1019 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | int Renderer11::getMinSwapInterval() const |
| 1023 | { |
daniel@transgaming.com | 8c7b1a9 | 2012-11-28 19:34:06 +0000 | [diff] [blame] | 1024 | return 0; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | int Renderer11::getMaxSwapInterval() const |
| 1028 | { |
daniel@transgaming.com | 8c7b1a9 | 2012-11-28 19:34:06 +0000 | [diff] [blame] | 1029 | return 4; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | int Renderer11::getMaxSupportedSamples() const |
| 1033 | { |
| 1034 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1035 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1036 | return 1; |
| 1037 | } |
| 1038 | |
daniel@transgaming.com | 31b13e1 | 2012-11-28 19:34:30 +0000 | [diff] [blame] | 1039 | bool Renderer11::copyToRenderTarget(TextureStorage2D *dest, TextureStorage2D *source) |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 1040 | { |
| 1041 | // TODO |
| 1042 | UNIMPLEMENTED(); |
| 1043 | return false; |
| 1044 | } |
| 1045 | |
daniel@transgaming.com | 31b13e1 | 2012-11-28 19:34:30 +0000 | [diff] [blame] | 1046 | bool Renderer11::copyToRenderTarget(TextureStorageCubeMap *dest, TextureStorageCubeMap *source) |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 1047 | { |
| 1048 | // TODO |
| 1049 | UNIMPLEMENTED(); |
| 1050 | return false; |
| 1051 | } |
| 1052 | |
daniel@transgaming.com | 3838088 | 2012-11-28 19:36:39 +0000 | [diff] [blame] | 1053 | bool Renderer11::copyImage(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, |
| 1054 | GLint xoffset, GLint yoffset, TextureStorage2D *storage, GLint level) |
| 1055 | { |
| 1056 | // TODO |
| 1057 | UNIMPLEMENTED(); |
| 1058 | return false; |
| 1059 | } |
| 1060 | |
| 1061 | bool Renderer11::copyImage(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, |
| 1062 | GLint xoffset, GLint yoffset, TextureStorageCubeMap *storage, GLenum target, GLint level) |
| 1063 | { |
| 1064 | // TODO |
| 1065 | UNIMPLEMENTED(); |
| 1066 | return false; |
| 1067 | } |
| 1068 | |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 1069 | RenderTarget *Renderer11::createRenderTarget(SwapChain *swapChain, bool depth) |
| 1070 | { |
daniel@transgaming.com | b6b27bc | 2012-11-28 20:54:30 +0000 | [diff] [blame] | 1071 | SwapChain11 *swapChain11 = SwapChain11::makeSwapChain11(swapChain); |
| 1072 | RenderTarget11 *renderTarget = NULL; |
| 1073 | if (depth) |
| 1074 | { |
| 1075 | renderTarget = new RenderTarget11(this, swapChain11->getDepthStencil(), swapChain11->getWidth(), swapChain11->getHeight()); |
| 1076 | } |
| 1077 | else |
| 1078 | { |
| 1079 | renderTarget = new RenderTarget11(this, swapChain11->getRenderTarget(), swapChain11->getWidth(), swapChain11->getHeight()); |
| 1080 | } |
| 1081 | return renderTarget; |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | RenderTarget *Renderer11::createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth) |
| 1085 | { |
| 1086 | // TODO |
| 1087 | UNIMPLEMENTED(); |
| 1088 | return NULL; |
| 1089 | } |
| 1090 | |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 1091 | ShaderExecutable *Renderer11::loadExecutable(const DWORD *function, size_t length, GLenum type, void *data) |
| 1092 | { |
| 1093 | // TODO |
| 1094 | UNIMPLEMENTED(); |
| 1095 | return NULL; |
| 1096 | } |
| 1097 | |
daniel@transgaming.com | a9c7142 | 2012-11-28 20:58:45 +0000 | [diff] [blame] | 1098 | ShaderExecutable *Renderer11::compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, GLenum type) |
| 1099 | { |
| 1100 | // TODO |
| 1101 | UNIMPLEMENTED(); |
| 1102 | return NULL; |
| 1103 | } |
| 1104 | |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 1105 | bool Renderer11::blitRect(gl::Framebuffer *readTarget, gl::Rectangle *readRect, gl::Framebuffer *drawTarget, gl::Rectangle *drawRect, |
| 1106 | bool blitRenderTarget, bool blitDepthStencil) |
| 1107 | { |
| 1108 | // TODO |
| 1109 | UNIMPLEMENTED(); |
| 1110 | return false; |
| 1111 | } |
| 1112 | |
| 1113 | void Renderer11::readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, |
| 1114 | GLsizei outputPitch, bool packReverseRowOrder, GLint packAlignment, void* pixels) |
| 1115 | { |
| 1116 | // TODO |
| 1117 | UNIMPLEMENTED(); |
| 1118 | return; |
| 1119 | } |
| 1120 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1121 | } |