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