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 | |
daniel@transgaming.com | 22ada2c | 2013-01-11 04:07:12 +0000 | [diff] [blame^] | 657 | mDeviceContext->IASetIndexBuffer(indexBuffer->getBuffer(), indexBuffer->getIndexFormat(), indexInfo->startOffset); |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 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 | { |
daniel@transgaming.com | 9f7ede6 | 2013-01-11 04:07:06 +0000 | [diff] [blame] | 678 | mDeviceContext->DrawIndexed(count, 0, -static_cast<int>(indexInfo.minIndex)); |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 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 | |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 720 | unsigned int *data = reinterpret_cast<unsigned int*>(mappedMemory); |
| 721 | |
| 722 | switch (type) |
| 723 | { |
| 724 | case GL_NONE: // Non-indexed draw |
| 725 | for (int i = 0; i < count; i++) |
| 726 | { |
| 727 | data[i] = i; |
| 728 | } |
| 729 | data[count] = 0; |
| 730 | break; |
| 731 | case GL_UNSIGNED_BYTE: |
| 732 | for (int i = 0; i < count; i++) |
| 733 | { |
| 734 | data[i] = static_cast<const GLubyte*>(indices)[i]; |
| 735 | } |
| 736 | data[count] = static_cast<const GLubyte*>(indices)[0]; |
| 737 | break; |
| 738 | case GL_UNSIGNED_SHORT: |
| 739 | for (int i = 0; i < count; i++) |
| 740 | { |
| 741 | data[i] = static_cast<const GLushort*>(indices)[i]; |
| 742 | } |
| 743 | data[count] = static_cast<const GLushort*>(indices)[0]; |
| 744 | break; |
| 745 | case GL_UNSIGNED_INT: |
| 746 | for (int i = 0; i < count; i++) |
| 747 | { |
| 748 | data[i] = static_cast<const GLuint*>(indices)[i]; |
| 749 | } |
| 750 | data[count] = static_cast<const GLuint*>(indices)[0]; |
| 751 | break; |
| 752 | default: UNREACHABLE(); |
| 753 | } |
| 754 | |
| 755 | if (!mLineLoopIB->unmapBuffer()) |
| 756 | { |
| 757 | ERR("Could not unmap index buffer for GL_LINE_LOOP."); |
| 758 | return error(GL_OUT_OF_MEMORY); |
| 759 | } |
| 760 | |
| 761 | if (mAppliedIBSerial != mLineLoopIB->getSerial()) |
| 762 | { |
| 763 | IndexBuffer11 *indexBuffer = IndexBuffer11::makeIndexBuffer11(mLineLoopIB->getIndexBuffer()); |
| 764 | |
daniel@transgaming.com | 22ada2c | 2013-01-11 04:07:12 +0000 | [diff] [blame^] | 765 | mDeviceContext->IASetIndexBuffer(indexBuffer->getBuffer(), indexBuffer->getIndexFormat(), offset); |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 766 | mAppliedIBSerial = mLineLoopIB->getSerial(); |
| 767 | } |
| 768 | |
| 769 | mDeviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINELIST); |
| 770 | mDeviceContext->DrawIndexed(count, 0, -minIndex); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 771 | } |
| 772 | |
daniel@transgaming.com | 5fbf177 | 2012-11-28 20:54:43 +0000 | [diff] [blame] | 773 | void Renderer11::applyShaders(gl::ProgramBinary *programBinary) |
| 774 | { |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 775 | unsigned int programBinarySerial = programBinary->getSerial(); |
| 776 | if (programBinarySerial != mAppliedProgramBinarySerial) |
| 777 | { |
| 778 | ShaderExecutable *vertexExe = programBinary->getVertexExecutable(); |
| 779 | ShaderExecutable *pixelExe = programBinary->getPixelExecutable(); |
daniel@transgaming.com | d4b2db2 | 2012-11-28 21:05:15 +0000 | [diff] [blame] | 780 | |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 781 | ID3D11VertexShader *vertexShader = NULL; |
| 782 | if (vertexExe) vertexShader = ShaderExecutable11::makeShaderExecutable11(vertexExe)->getVertexShader(); |
daniel@transgaming.com | d4b2db2 | 2012-11-28 21:05:15 +0000 | [diff] [blame] | 783 | |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 784 | ID3D11PixelShader *pixelShader = NULL; |
| 785 | if (pixelExe) pixelShader = ShaderExecutable11::makeShaderExecutable11(pixelExe)->getPixelShader(); |
daniel@transgaming.com | d4b2db2 | 2012-11-28 21:05:15 +0000 | [diff] [blame] | 786 | |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 787 | mDeviceContext->PSSetShader(pixelShader, NULL, 0); |
| 788 | mDeviceContext->VSSetShader(vertexShader, NULL, 0); |
| 789 | programBinary->dirtyAllUniforms(); |
| 790 | |
| 791 | mAppliedProgramBinarySerial = programBinarySerial; |
| 792 | } |
daniel@transgaming.com | 5fbf177 | 2012-11-28 20:54:43 +0000 | [diff] [blame] | 793 | } |
| 794 | |
daniel@transgaming.com | ab1c146 | 2012-12-20 21:08:30 +0000 | [diff] [blame] | 795 | void Renderer11::applyUniforms(const gl::UniformArray *uniformArray) |
| 796 | { |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 797 | D3D11_BUFFER_DESC constantBufferDescription = {0}; |
| 798 | constantBufferDescription.ByteWidth = D3D10_REQ_CONSTANT_BUFFER_ELEMENT_COUNT * sizeof(float[4]); |
| 799 | constantBufferDescription.Usage = D3D11_USAGE_DYNAMIC; |
| 800 | constantBufferDescription.BindFlags = D3D11_BIND_CONSTANT_BUFFER; |
| 801 | constantBufferDescription.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; |
| 802 | constantBufferDescription.MiscFlags = 0; |
| 803 | constantBufferDescription.StructureByteStride = 0; |
| 804 | |
| 805 | ID3D11Buffer *constantBufferVS = NULL; |
| 806 | HRESULT result = mDevice->CreateBuffer(&constantBufferDescription, NULL, &constantBufferVS); |
| 807 | ASSERT(SUCCEEDED(result)); |
| 808 | |
| 809 | ID3D11Buffer *constantBufferPS = NULL; |
| 810 | result = mDevice->CreateBuffer(&constantBufferDescription, NULL, &constantBufferPS); |
| 811 | ASSERT(SUCCEEDED(result)); |
| 812 | |
| 813 | D3D11_MAPPED_SUBRESOURCE mapVS = {0}; |
| 814 | result = mDeviceContext->Map(constantBufferVS, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapVS); |
| 815 | ASSERT(SUCCEEDED(result)); |
| 816 | |
| 817 | D3D11_MAPPED_SUBRESOURCE mapPS = {0}; |
| 818 | result = mDeviceContext->Map(constantBufferPS, 0, D3D11_MAP_WRITE_DISCARD, 0, &mapPS); |
| 819 | ASSERT(SUCCEEDED(result)); |
| 820 | |
| 821 | float (*cVS)[4] = (float(*)[4])mapVS.pData; |
| 822 | float (*cPS)[4] = (float(*)[4])mapPS.pData; |
| 823 | |
| 824 | 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] | 825 | { |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 826 | const gl::Uniform *uniform = *uniform_iterator; |
| 827 | GLfloat (*f)[4] = (GLfloat(*)[4])uniform->data; |
| 828 | |
| 829 | switch (uniform->type) |
| 830 | { |
daniel@transgaming.com | da8d380 | 2012-12-20 21:12:55 +0000 | [diff] [blame] | 831 | case GL_SAMPLER_2D: |
| 832 | case GL_SAMPLER_CUBE: |
| 833 | break; |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 834 | case GL_FLOAT: |
| 835 | case GL_FLOAT_VEC2: |
| 836 | case GL_FLOAT_VEC3: |
| 837 | case GL_FLOAT_VEC4: |
| 838 | case GL_FLOAT_MAT2: |
| 839 | case GL_FLOAT_MAT3: |
| 840 | case GL_FLOAT_MAT4: |
| 841 | if (uniform->vs.registerCount) |
| 842 | { |
daniel@transgaming.com | e6d12e9 | 2012-12-20 21:12:47 +0000 | [diff] [blame] | 843 | for (unsigned int i = 0; i < uniform->vs.registerCount; i++) |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 844 | { |
| 845 | cVS[uniform->vs.registerIndex + i][0] = f[i][0]; |
| 846 | cVS[uniform->vs.registerIndex + i][1] = f[i][1]; |
| 847 | cVS[uniform->vs.registerIndex + i][2] = f[i][2]; |
| 848 | cVS[uniform->vs.registerIndex + i][3] = f[i][3]; |
| 849 | } |
| 850 | } |
| 851 | if (uniform->ps.registerCount) |
| 852 | { |
daniel@transgaming.com | e6d12e9 | 2012-12-20 21:12:47 +0000 | [diff] [blame] | 853 | for (unsigned int i = 0; i < uniform->ps.registerCount; i++) |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 854 | { |
| 855 | cPS[uniform->ps.registerIndex + i][0] = f[i][0]; |
| 856 | cPS[uniform->ps.registerIndex + i][1] = f[i][1]; |
| 857 | cPS[uniform->ps.registerIndex + i][2] = f[i][2]; |
| 858 | cPS[uniform->ps.registerIndex + i][3] = f[i][3]; |
| 859 | } |
| 860 | } |
| 861 | break; |
| 862 | default: |
| 863 | UNIMPLEMENTED(); // FIXME |
| 864 | UNREACHABLE(); |
| 865 | } |
daniel@transgaming.com | ab1c146 | 2012-12-20 21:08:30 +0000 | [diff] [blame] | 866 | } |
daniel@transgaming.com | 873f28a | 2012-12-20 21:12:42 +0000 | [diff] [blame] | 867 | |
| 868 | mDeviceContext->Unmap(constantBufferVS, 0); |
| 869 | mDeviceContext->VSSetConstantBuffers(0, 1, &constantBufferVS); |
| 870 | constantBufferVS->Release(); |
| 871 | |
| 872 | mDeviceContext->Unmap(constantBufferPS, 0); |
| 873 | mDeviceContext->PSSetConstantBuffers(0, 1, &constantBufferPS); |
| 874 | constantBufferPS->Release(); |
daniel@transgaming.com | ab1c146 | 2012-12-20 21:08:30 +0000 | [diff] [blame] | 875 | } |
| 876 | |
daniel@transgaming.com | 084a257 | 2012-11-28 20:55:17 +0000 | [diff] [blame] | 877 | void Renderer11::clear(const gl::ClearParameters &clearParams, gl::Framebuffer *frameBuffer) |
daniel@transgaming.com | d084c62 | 2012-11-28 19:36:05 +0000 | [diff] [blame] | 878 | { |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 879 | if (clearParams.mask & GL_COLOR_BUFFER_BIT) |
| 880 | { |
| 881 | gl::Renderbuffer *renderbufferObject = frameBuffer->getColorbuffer(); |
| 882 | if (renderbufferObject) |
| 883 | { |
| 884 | RenderTarget11 *renderTarget = RenderTarget11::makeRenderTarget11(renderbufferObject->getRenderTarget()); |
| 885 | if (!renderTarget) |
| 886 | { |
| 887 | ERR("render target pointer unexpectedly null."); |
| 888 | return; |
| 889 | } |
| 890 | |
| 891 | ID3D11RenderTargetView *framebufferRTV = renderTarget->getRenderTargetView(); |
| 892 | if (!framebufferRTV) |
| 893 | { |
| 894 | ERR("render target view pointer unexpectedly null."); |
| 895 | return; |
| 896 | } |
| 897 | |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 898 | if (mScissorEnabled && (mCurScissor.x > 0 || mCurScissor.y > 0 || |
| 899 | mCurScissor.x + mCurScissor.width < renderTarget->getWidth() || |
| 900 | mCurScissor.y + mCurScissor.height < renderTarget->getHeight())) |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 901 | { |
| 902 | // TODO: clearing of subregion of render target |
| 903 | UNIMPLEMENTED(); |
| 904 | } |
| 905 | |
| 906 | bool alphaUnmasked = (gl::GetAlphaSize(mRenderTargetDesc.format) == 0) || clearParams.colorMaskAlpha; |
| 907 | const bool needMaskedColorClear = (clearParams.mask & GL_COLOR_BUFFER_BIT) && |
| 908 | !(clearParams.colorMaskRed && clearParams.colorMaskGreen && |
| 909 | clearParams.colorMaskBlue && alphaUnmasked); |
| 910 | |
| 911 | if (needMaskedColorClear) |
| 912 | { |
| 913 | // TODO: masked color clearing |
| 914 | UNIMPLEMENTED(); |
| 915 | } |
| 916 | else |
| 917 | { |
| 918 | const float clearValues[4] = { clearParams.colorClearValue.red, |
| 919 | clearParams.colorClearValue.green, |
| 920 | clearParams.colorClearValue.blue, |
| 921 | clearParams.colorClearValue.alpha }; |
| 922 | mDeviceContext->ClearRenderTargetView(framebufferRTV, clearValues); |
| 923 | } |
| 924 | |
| 925 | framebufferRTV->Release(); |
| 926 | } |
| 927 | } |
| 928 | if (clearParams.mask & GL_DEPTH_BUFFER_BIT || clearParams.mask & GL_STENCIL_BUFFER_BIT) |
| 929 | { |
| 930 | gl::Renderbuffer *renderbufferObject = frameBuffer->getDepthOrStencilbuffer(); |
| 931 | if (renderbufferObject) |
| 932 | { |
daniel@transgaming.com | d0f82bc | 2012-12-20 21:11:42 +0000 | [diff] [blame] | 933 | RenderTarget11 *renderTarget = RenderTarget11::makeRenderTarget11(renderbufferObject->getDepthStencil()); |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 934 | if (!renderTarget) |
| 935 | { |
| 936 | ERR("render target pointer unexpectedly null."); |
| 937 | return; |
| 938 | } |
| 939 | |
| 940 | ID3D11DepthStencilView *framebufferDSV = renderTarget->getDepthStencilView(); |
| 941 | if (!framebufferDSV) |
| 942 | { |
| 943 | ERR("depth stencil view pointer unexpectedly null."); |
| 944 | return; |
| 945 | } |
| 946 | |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 947 | if (mScissorEnabled && (mCurScissor.x > 0 || mCurScissor.y > 0 || |
| 948 | mCurScissor.x + mCurScissor.width < renderTarget->getWidth() || |
| 949 | mCurScissor.y + mCurScissor.height < renderTarget->getHeight())) |
daniel@transgaming.com | 54e6754 | 2012-11-28 21:02:31 +0000 | [diff] [blame] | 950 | { |
| 951 | // TODO: clearing of subregion of depth stencil view |
| 952 | UNIMPLEMENTED(); |
| 953 | } |
| 954 | |
| 955 | unsigned int stencilUnmasked = 0x0; |
| 956 | if ((clearParams.mask & GL_STENCIL_BUFFER_BIT) && frameBuffer->hasStencil()) |
| 957 | { |
| 958 | unsigned int stencilSize = gl::GetStencilSize(frameBuffer->getStencilbuffer()->getActualFormat()); |
| 959 | stencilUnmasked = (0x1 << stencilSize) - 1; |
| 960 | } |
| 961 | |
| 962 | const bool needMaskedStencilClear = (clearParams.mask & GL_STENCIL_BUFFER_BIT) && |
| 963 | (clearParams.stencilWriteMask & stencilUnmasked) != stencilUnmasked; |
| 964 | |
| 965 | if (needMaskedStencilClear) |
| 966 | { |
| 967 | // TODO: masked clearing of depth stencil |
| 968 | UNIMPLEMENTED(); |
| 969 | } |
| 970 | else |
| 971 | { |
| 972 | UINT clearFlags = 0; |
| 973 | if (clearParams.mask & GL_DEPTH_BUFFER_BIT) |
| 974 | { |
| 975 | clearFlags |= D3D11_CLEAR_DEPTH; |
| 976 | } |
| 977 | if (clearParams.mask & GL_STENCIL_BUFFER_BIT) |
| 978 | { |
| 979 | clearFlags |= D3D11_CLEAR_STENCIL; |
| 980 | } |
| 981 | |
| 982 | float depthClear = clearParams.depthClearValue; |
| 983 | UINT8 stencilClear = clearParams.stencilClearValue & 0x000000FF; |
| 984 | |
| 985 | mDeviceContext->ClearDepthStencilView(framebufferDSV, clearFlags, depthClear, stencilClear); |
| 986 | } |
| 987 | |
| 988 | framebufferDSV->Release(); |
| 989 | } |
| 990 | } |
daniel@transgaming.com | d084c62 | 2012-11-28 19:36:05 +0000 | [diff] [blame] | 991 | } |
| 992 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 993 | void Renderer11::markAllStateDirty() |
| 994 | { |
daniel@transgaming.com | 9a06737 | 2012-12-20 20:55:24 +0000 | [diff] [blame] | 995 | mAppliedRenderTargetSerial = 0; |
| 996 | mAppliedDepthbufferSerial = 0; |
| 997 | mAppliedStencilbufferSerial = 0; |
daniel@transgaming.com | 7b6b83e | 2012-11-28 21:00:30 +0000 | [diff] [blame] | 998 | mDepthStencilInitialized = false; |
| 999 | mRenderTargetDescInitialized = false; |
| 1000 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 1001 | mForceSetBlendState = true; |
| 1002 | mForceSetRasterState = true; |
| 1003 | mForceSetDepthStencilState = true; |
| 1004 | mForceSetScissor = true; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 1005 | mForceSetViewport = true; |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1006 | |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 1007 | mAppliedIBSerial = 0; |
daniel@transgaming.com | e499141 | 2012-12-20 20:55:34 +0000 | [diff] [blame] | 1008 | mAppliedProgramBinarySerial = 0; |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1011 | void Renderer11::releaseDeviceResources() |
| 1012 | { |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 1013 | mStateCache.clear(); |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 1014 | mInputLayoutCache.clear(); |
| 1015 | |
| 1016 | delete mVertexDataManager; |
| 1017 | mVertexDataManager = NULL; |
| 1018 | |
| 1019 | delete mIndexDataManager; |
| 1020 | mIndexDataManager = NULL; |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 1021 | |
| 1022 | delete mLineLoopIB; |
| 1023 | mLineLoopIB = NULL; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | void Renderer11::markDeviceLost() |
| 1027 | { |
| 1028 | mDeviceLost = true; |
| 1029 | } |
| 1030 | |
| 1031 | bool Renderer11::isDeviceLost() |
| 1032 | { |
| 1033 | return mDeviceLost; |
| 1034 | } |
| 1035 | |
| 1036 | // set notify to true to broadcast a message to all contexts of the device loss |
| 1037 | bool Renderer11::testDeviceLost(bool notify) |
| 1038 | { |
| 1039 | bool isLost = false; |
| 1040 | |
| 1041 | // TODO |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 1042 | //UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1043 | |
| 1044 | if (isLost) |
| 1045 | { |
| 1046 | // ensure we note the device loss -- |
| 1047 | // we'll probably get this done again by markDeviceLost |
| 1048 | // but best to remember it! |
| 1049 | // Note that we don't want to clear the device loss status here |
| 1050 | // -- this needs to be done by resetDevice |
| 1051 | mDeviceLost = true; |
| 1052 | if (notify) |
| 1053 | { |
| 1054 | mDisplay->notifyDeviceLost(); |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | return isLost; |
| 1059 | } |
| 1060 | |
| 1061 | bool Renderer11::testDeviceResettable() |
| 1062 | { |
| 1063 | HRESULT status = D3D_OK; |
| 1064 | |
| 1065 | // TODO |
| 1066 | UNIMPLEMENTED(); |
| 1067 | |
| 1068 | switch (status) |
| 1069 | { |
| 1070 | case D3DERR_DEVICENOTRESET: |
| 1071 | case D3DERR_DEVICEHUNG: |
| 1072 | return true; |
| 1073 | default: |
| 1074 | return false; |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | bool Renderer11::resetDevice() |
| 1079 | { |
| 1080 | releaseDeviceResources(); |
| 1081 | |
| 1082 | // TODO |
| 1083 | UNIMPLEMENTED(); |
| 1084 | |
| 1085 | // reset device defaults |
| 1086 | initializeDevice(); |
| 1087 | mDeviceLost = false; |
| 1088 | |
| 1089 | return true; |
| 1090 | } |
| 1091 | |
| 1092 | DWORD Renderer11::getAdapterVendor() const |
| 1093 | { |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1094 | return mAdapterDescription.VendorId; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | const char *Renderer11::getAdapterDescription() const |
| 1098 | { |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1099 | return mDescription; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | GUID Renderer11::getAdapterIdentifier() const |
| 1103 | { |
| 1104 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1105 | // UNIMPLEMENTED(); |
| 1106 | GUID foo = {0}; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1107 | return foo; |
| 1108 | } |
| 1109 | |
| 1110 | bool Renderer11::getDXT1TextureSupport() |
| 1111 | { |
| 1112 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1113 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1114 | return false; |
| 1115 | } |
| 1116 | |
| 1117 | bool Renderer11::getDXT3TextureSupport() |
| 1118 | { |
| 1119 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1120 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1121 | return false; |
| 1122 | } |
| 1123 | |
| 1124 | bool Renderer11::getDXT5TextureSupport() |
| 1125 | { |
| 1126 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1127 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1128 | return false; |
| 1129 | } |
| 1130 | |
| 1131 | bool Renderer11::getDepthTextureSupport() const |
| 1132 | { |
| 1133 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1134 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1135 | return false; |
| 1136 | } |
| 1137 | |
| 1138 | bool Renderer11::getFloat32TextureSupport(bool *filtering, bool *renderable) |
| 1139 | { |
| 1140 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1141 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1142 | |
| 1143 | *filtering = false; |
| 1144 | *renderable = false; |
| 1145 | return false; |
| 1146 | } |
| 1147 | |
| 1148 | bool Renderer11::getFloat16TextureSupport(bool *filtering, bool *renderable) |
| 1149 | { |
| 1150 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1151 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1152 | |
| 1153 | *filtering = false; |
| 1154 | *renderable = false; |
| 1155 | return false; |
| 1156 | } |
| 1157 | |
| 1158 | bool Renderer11::getLuminanceTextureSupport() |
| 1159 | { |
| 1160 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1161 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1162 | return false; |
| 1163 | } |
| 1164 | |
| 1165 | bool Renderer11::getLuminanceAlphaTextureSupport() |
| 1166 | { |
| 1167 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1168 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1169 | return false; |
| 1170 | } |
| 1171 | |
| 1172 | bool Renderer11::getTextureFilterAnisotropySupport() const |
| 1173 | { |
| 1174 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1175 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1176 | return false; |
| 1177 | } |
| 1178 | |
| 1179 | float Renderer11::getTextureMaxAnisotropy() const |
| 1180 | { |
| 1181 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1182 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1183 | return 1.0f; |
| 1184 | } |
| 1185 | |
| 1186 | bool Renderer11::getEventQuerySupport() |
| 1187 | { |
| 1188 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1189 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1190 | return false; |
| 1191 | } |
| 1192 | |
| 1193 | bool Renderer11::getVertexTextureSupport() const |
| 1194 | { |
| 1195 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1196 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1197 | return false; |
| 1198 | } |
| 1199 | |
| 1200 | bool Renderer11::getNonPower2TextureSupport() const |
| 1201 | { |
| 1202 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1203 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1204 | return false; |
| 1205 | } |
| 1206 | |
| 1207 | bool Renderer11::getOcclusionQuerySupport() const |
| 1208 | { |
| 1209 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1210 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1211 | return false; |
| 1212 | } |
| 1213 | |
| 1214 | bool Renderer11::getInstancingSupport() const |
| 1215 | { |
| 1216 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1217 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1218 | return false; |
| 1219 | } |
| 1220 | |
| 1221 | bool Renderer11::getShareHandleSupport() const |
| 1222 | { |
| 1223 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1224 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1225 | |
| 1226 | // PIX doesn't seem to support using share handles, so disable them. |
| 1227 | return false && !gl::perfActive(); |
| 1228 | } |
| 1229 | |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 1230 | int Renderer11::getMajorShaderModel() const |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1231 | { |
daniel@transgaming.com | 9549bea | 2012-11-28 20:57:23 +0000 | [diff] [blame] | 1232 | switch (mFeatureLevel) |
| 1233 | { |
| 1234 | case D3D_FEATURE_LEVEL_11_0: return D3D11_SHADER_MAJOR_VERSION; // 5 |
| 1235 | case D3D_FEATURE_LEVEL_10_1: |
| 1236 | case D3D_FEATURE_LEVEL_10_0: return D3D10_SHADER_MAJOR_VERSION; // 4 |
| 1237 | default: UNREACHABLE(); return 0; |
| 1238 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | float Renderer11::getMaxPointSize() const |
| 1242 | { |
| 1243 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1244 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1245 | return 1.0f; |
| 1246 | } |
| 1247 | |
| 1248 | int Renderer11::getMaxTextureWidth() const |
| 1249 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 1250 | switch (mFeatureLevel) |
| 1251 | { |
| 1252 | case D3D_FEATURE_LEVEL_11_0: return D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 16384 |
| 1253 | case D3D_FEATURE_LEVEL_10_1: |
| 1254 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 8192 |
| 1255 | default: UNREACHABLE(); return 0; |
| 1256 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | int Renderer11::getMaxTextureHeight() const |
| 1260 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 1261 | switch (mFeatureLevel) |
| 1262 | { |
| 1263 | case D3D_FEATURE_LEVEL_11_0: return D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 16384 |
| 1264 | case D3D_FEATURE_LEVEL_10_1: |
| 1265 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION; // 8192 |
| 1266 | default: UNREACHABLE(); return 0; |
| 1267 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | bool Renderer11::get32BitIndexSupport() const |
| 1271 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 1272 | switch (mFeatureLevel) |
| 1273 | { |
| 1274 | case D3D_FEATURE_LEVEL_11_0: |
| 1275 | case D3D_FEATURE_LEVEL_10_1: |
| 1276 | case D3D_FEATURE_LEVEL_10_0: return D3D10_REQ_DRAWINDEXED_INDEX_COUNT_2_TO_EXP >= 32; // true |
| 1277 | default: UNREACHABLE(); return false; |
| 1278 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | int Renderer11::getMinSwapInterval() const |
| 1282 | { |
daniel@transgaming.com | 8c7b1a9 | 2012-11-28 19:34:06 +0000 | [diff] [blame] | 1283 | return 0; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | int Renderer11::getMaxSwapInterval() const |
| 1287 | { |
daniel@transgaming.com | 8c7b1a9 | 2012-11-28 19:34:06 +0000 | [diff] [blame] | 1288 | return 4; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | int Renderer11::getMaxSupportedSamples() const |
| 1292 | { |
| 1293 | // TODO |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 1294 | // UNIMPLEMENTED(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1295 | return 1; |
| 1296 | } |
| 1297 | |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 1298 | bool Renderer11::copyToRenderTarget(TextureStorageInterface2D *dest, TextureStorageInterface2D *source) |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 1299 | { |
daniel@transgaming.com | b1c208f | 2013-01-11 04:06:49 +0000 | [diff] [blame] | 1300 | if (source && dest) |
| 1301 | { |
| 1302 | TextureStorage11_2D *source11 = TextureStorage11_2D::makeTextureStorage11_2D(source->getStorageInstance()); |
| 1303 | TextureStorage11_2D *dest11 = TextureStorage11_2D::makeTextureStorage11_2D(dest->getStorageInstance()); |
| 1304 | |
daniel@transgaming.com | e9cf5e7 | 2013-01-11 04:06:55 +0000 | [diff] [blame] | 1305 | mDeviceContext->CopyResource(dest11->getBaseTexture(), source11->getBaseTexture()); |
daniel@transgaming.com | b1c208f | 2013-01-11 04:06:49 +0000 | [diff] [blame] | 1306 | return true; |
| 1307 | } |
| 1308 | |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 1309 | return false; |
| 1310 | } |
| 1311 | |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 1312 | bool Renderer11::copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source) |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 1313 | { |
daniel@transgaming.com | b1c208f | 2013-01-11 04:06:49 +0000 | [diff] [blame] | 1314 | if (source && dest) |
| 1315 | { |
daniel@transgaming.com | e9cf5e7 | 2013-01-11 04:06:55 +0000 | [diff] [blame] | 1316 | TextureStorage11_Cube *source11 = TextureStorage11_Cube::makeTextureStorage11_Cube(source->getStorageInstance()); |
| 1317 | TextureStorage11_Cube *dest11 = TextureStorage11_Cube::makeTextureStorage11_Cube(dest->getStorageInstance()); |
daniel@transgaming.com | b1c208f | 2013-01-11 04:06:49 +0000 | [diff] [blame] | 1318 | |
daniel@transgaming.com | e9cf5e7 | 2013-01-11 04:06:55 +0000 | [diff] [blame] | 1319 | mDeviceContext->CopyResource(dest11->getBaseTexture(), source11->getBaseTexture()); |
daniel@transgaming.com | b1c208f | 2013-01-11 04:06:49 +0000 | [diff] [blame] | 1320 | return true; |
| 1321 | } |
| 1322 | |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 1323 | return false; |
| 1324 | } |
| 1325 | |
daniel@transgaming.com | 3838088 | 2012-11-28 19:36:39 +0000 | [diff] [blame] | 1326 | bool Renderer11::copyImage(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 1327 | GLint xoffset, GLint yoffset, TextureStorageInterface2D *storage, GLint level) |
daniel@transgaming.com | 3838088 | 2012-11-28 19:36:39 +0000 | [diff] [blame] | 1328 | { |
| 1329 | // TODO |
| 1330 | UNIMPLEMENTED(); |
| 1331 | return false; |
| 1332 | } |
| 1333 | |
| 1334 | bool Renderer11::copyImage(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 1335 | GLint xoffset, GLint yoffset, TextureStorageInterfaceCube *storage, GLenum target, GLint level) |
daniel@transgaming.com | 3838088 | 2012-11-28 19:36:39 +0000 | [diff] [blame] | 1336 | { |
| 1337 | // TODO |
| 1338 | UNIMPLEMENTED(); |
| 1339 | return false; |
| 1340 | } |
| 1341 | |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 1342 | RenderTarget *Renderer11::createRenderTarget(SwapChain *swapChain, bool depth) |
| 1343 | { |
daniel@transgaming.com | b6b27bc | 2012-11-28 20:54:30 +0000 | [diff] [blame] | 1344 | SwapChain11 *swapChain11 = SwapChain11::makeSwapChain11(swapChain); |
| 1345 | RenderTarget11 *renderTarget = NULL; |
| 1346 | if (depth) |
| 1347 | { |
| 1348 | renderTarget = new RenderTarget11(this, swapChain11->getDepthStencil(), swapChain11->getWidth(), swapChain11->getHeight()); |
| 1349 | } |
| 1350 | else |
| 1351 | { |
| 1352 | renderTarget = new RenderTarget11(this, swapChain11->getRenderTarget(), swapChain11->getWidth(), swapChain11->getHeight()); |
| 1353 | } |
| 1354 | return renderTarget; |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | RenderTarget *Renderer11::createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth) |
| 1358 | { |
| 1359 | // TODO |
| 1360 | UNIMPLEMENTED(); |
| 1361 | return NULL; |
| 1362 | } |
| 1363 | |
daniel@transgaming.com | 2275f91 | 2012-12-20 21:13:22 +0000 | [diff] [blame] | 1364 | ShaderExecutable *Renderer11::loadExecutable(const void *function, size_t length, GLenum type) |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 1365 | { |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 1366 | ShaderExecutable11 *executable = NULL; |
| 1367 | |
| 1368 | switch (type) |
| 1369 | { |
| 1370 | case GL_VERTEX_SHADER: |
| 1371 | { |
| 1372 | ID3D11VertexShader *vshader = NULL; |
| 1373 | HRESULT result = mDevice->CreateVertexShader(function, length, NULL, &vshader); |
| 1374 | ASSERT(SUCCEEDED(result)); |
| 1375 | |
| 1376 | if (vshader) |
| 1377 | { |
daniel@transgaming.com | 7b18d0c | 2012-11-28 21:04:10 +0000 | [diff] [blame] | 1378 | executable = new ShaderExecutable11(function, length, vshader); |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 1379 | } |
| 1380 | } |
| 1381 | break; |
| 1382 | case GL_FRAGMENT_SHADER: |
| 1383 | { |
| 1384 | ID3D11PixelShader *pshader = NULL; |
| 1385 | HRESULT result = mDevice->CreatePixelShader(function, length, NULL, &pshader); |
| 1386 | ASSERT(SUCCEEDED(result)); |
| 1387 | |
| 1388 | if (pshader) |
| 1389 | { |
daniel@transgaming.com | 7b18d0c | 2012-11-28 21:04:10 +0000 | [diff] [blame] | 1390 | executable = new ShaderExecutable11(function, length, pshader); |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 1391 | } |
| 1392 | } |
| 1393 | break; |
| 1394 | default: |
| 1395 | UNREACHABLE(); |
| 1396 | break; |
| 1397 | } |
| 1398 | |
| 1399 | return executable; |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 1400 | } |
| 1401 | |
daniel@transgaming.com | a9c7142 | 2012-11-28 20:58:45 +0000 | [diff] [blame] | 1402 | ShaderExecutable *Renderer11::compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, GLenum type) |
| 1403 | { |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 1404 | const char *profile = NULL; |
| 1405 | |
| 1406 | switch (type) |
| 1407 | { |
| 1408 | case GL_VERTEX_SHADER: |
| 1409 | profile = "vs_4_0"; |
| 1410 | break; |
| 1411 | case GL_FRAGMENT_SHADER: |
| 1412 | profile = "ps_4_0"; |
| 1413 | break; |
| 1414 | default: |
| 1415 | UNREACHABLE(); |
| 1416 | return NULL; |
| 1417 | } |
| 1418 | |
daniel@transgaming.com | 25e16af | 2012-11-28 21:05:57 +0000 | [diff] [blame] | 1419 | ID3DBlob *binary = compileToBinary(infoLog, shaderHLSL, profile, false); |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 1420 | if (!binary) |
| 1421 | return NULL; |
| 1422 | |
daniel@transgaming.com | 2275f91 | 2012-12-20 21:13:22 +0000 | [diff] [blame] | 1423 | ShaderExecutable *executable = loadExecutable((DWORD *)binary->GetBufferPointer(), binary->GetBufferSize(), type); |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 1424 | binary->Release(); |
| 1425 | |
| 1426 | return executable; |
| 1427 | } |
| 1428 | |
daniel@transgaming.com | 3f255b4 | 2012-12-20 21:07:35 +0000 | [diff] [blame] | 1429 | VertexBuffer *Renderer11::createVertexBuffer() |
| 1430 | { |
daniel@transgaming.com | 2c4d070 | 2012-12-20 21:08:51 +0000 | [diff] [blame] | 1431 | return new VertexBuffer11(this); |
daniel@transgaming.com | 3f255b4 | 2012-12-20 21:07:35 +0000 | [diff] [blame] | 1432 | } |
| 1433 | |
daniel@transgaming.com | 0b6d774 | 2012-12-20 21:09:47 +0000 | [diff] [blame] | 1434 | IndexBuffer *Renderer11::createIndexBuffer() |
| 1435 | { |
daniel@transgaming.com | 11c2af5 | 2012-12-20 21:10:01 +0000 | [diff] [blame] | 1436 | return new IndexBuffer11(this); |
daniel@transgaming.com | 0b6d774 | 2012-12-20 21:09:47 +0000 | [diff] [blame] | 1437 | } |
| 1438 | |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 1439 | bool Renderer11::blitRect(gl::Framebuffer *readTarget, gl::Rectangle *readRect, gl::Framebuffer *drawTarget, gl::Rectangle *drawRect, |
| 1440 | bool blitRenderTarget, bool blitDepthStencil) |
| 1441 | { |
| 1442 | // TODO |
| 1443 | UNIMPLEMENTED(); |
| 1444 | return false; |
| 1445 | } |
| 1446 | |
| 1447 | void Renderer11::readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, |
| 1448 | GLsizei outputPitch, bool packReverseRowOrder, GLint packAlignment, void* pixels) |
| 1449 | { |
| 1450 | // TODO |
| 1451 | UNIMPLEMENTED(); |
| 1452 | return; |
| 1453 | } |
| 1454 | |
daniel@transgaming.com | 244e183 | 2012-12-20 20:52:35 +0000 | [diff] [blame] | 1455 | Image *Renderer11::createImage() |
| 1456 | { |
daniel@transgaming.com | a8aac67 | 2012-12-20 21:08:00 +0000 | [diff] [blame] | 1457 | return new Image11(); |
daniel@transgaming.com | 244e183 | 2012-12-20 20:52:35 +0000 | [diff] [blame] | 1458 | } |
| 1459 | |
daniel@transgaming.com | f721fdb | 2012-12-20 20:53:11 +0000 | [diff] [blame] | 1460 | void Renderer11::generateMipmap(Image *dest, Image *src) |
| 1461 | { |
| 1462 | // TODO |
| 1463 | UNIMPLEMENTED(); |
| 1464 | return; |
| 1465 | } |
| 1466 | |
daniel@transgaming.com | 413d271 | 2012-12-20 21:11:04 +0000 | [diff] [blame] | 1467 | TextureStorage *Renderer11::createTextureStorage2D(SwapChain *swapChain) |
| 1468 | { |
| 1469 | // TODO |
| 1470 | UNIMPLEMENTED(); |
| 1471 | return NULL; |
| 1472 | } |
| 1473 | |
| 1474 | TextureStorage *Renderer11::createTextureStorage2D(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, GLsizei width, GLsizei height) |
| 1475 | { |
| 1476 | // TODO |
| 1477 | UNIMPLEMENTED(); |
| 1478 | return NULL; |
| 1479 | } |
| 1480 | |
| 1481 | TextureStorage *Renderer11::createTextureStorageCube(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, int size) |
| 1482 | { |
| 1483 | // TODO |
| 1484 | UNIMPLEMENTED(); |
| 1485 | return NULL; |
| 1486 | } |
| 1487 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1488 | } |