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