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 | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 27 | |
| 28 | #include "libEGL/Config.h" |
| 29 | #include "libEGL/Display.h" |
| 30 | |
| 31 | namespace rx |
| 32 | { |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 33 | static const DXGI_FORMAT RenderTargetFormats[] = |
| 34 | { |
| 35 | DXGI_FORMAT_R8G8B8A8_UNORM |
| 36 | }; |
| 37 | |
| 38 | static const DXGI_FORMAT DepthStencilFormats[] = |
| 39 | { |
| 40 | DXGI_FORMAT_D24_UNORM_S8_UINT |
| 41 | }; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 42 | |
| 43 | Renderer11::Renderer11(egl::Display *display, HDC hDc) : Renderer(display), mDc(hDc) |
| 44 | { |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 45 | mVertexDataManager = NULL; |
| 46 | mIndexDataManager = NULL; |
| 47 | |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 48 | mLineLoopIB = NULL; |
| 49 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 50 | mD3d11Module = NULL; |
| 51 | mDxgiModule = NULL; |
| 52 | |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 53 | mDeviceLost = false; |
| 54 | |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 55 | mDevice = NULL; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 56 | mDeviceContext = NULL; |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 57 | mDxgiAdapter = NULL; |
| 58 | mDxgiFactory = NULL; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | Renderer11::~Renderer11() |
| 62 | { |
| 63 | releaseDeviceResources(); |
| 64 | |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 65 | if (mDxgiFactory) |
| 66 | { |
| 67 | mDxgiFactory->Release(); |
| 68 | mDxgiFactory = NULL; |
| 69 | } |
| 70 | |
| 71 | if (mDxgiAdapter) |
| 72 | { |
| 73 | mDxgiAdapter->Release(); |
| 74 | mDxgiAdapter = NULL; |
| 75 | } |
| 76 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 77 | if (mDeviceContext) |
| 78 | { |
| 79 | mDeviceContext->Release(); |
| 80 | mDeviceContext = NULL; |
| 81 | } |
| 82 | |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 83 | if (mDevice) |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 84 | { |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 85 | mDevice->Release(); |
| 86 | mDevice = NULL; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | if (mD3d11Module) |
| 90 | { |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 91 | FreeLibrary(mD3d11Module); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 92 | mD3d11Module = NULL; |
| 93 | } |
| 94 | |
| 95 | if (mDxgiModule) |
| 96 | { |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 97 | FreeLibrary(mDxgiModule); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 98 | mDxgiModule = NULL; |
| 99 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 100 | } |
| 101 | |
daniel@transgaming.com | b64ed28 | 2012-11-28 20:54:02 +0000 | [diff] [blame] | 102 | Renderer11 *Renderer11::makeRenderer11(Renderer *renderer) |
| 103 | { |
| 104 | ASSERT(dynamic_cast<rx::Renderer11*>(renderer) != NULL); |
| 105 | return static_cast<rx::Renderer11*>(renderer); |
| 106 | } |
| 107 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 108 | EGLint Renderer11::initialize() |
| 109 | { |
daniel@transgaming.com | 25e16af | 2012-11-28 21:05:57 +0000 | [diff] [blame] | 110 | if (!initializeCompiler()) |
| 111 | { |
| 112 | return EGL_NOT_INITIALIZED; |
| 113 | } |
| 114 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 115 | mDxgiModule = LoadLibrary(TEXT("dxgi.dll")); |
| 116 | mD3d11Module = LoadLibrary(TEXT("d3d11.dll")); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 117 | |
| 118 | if (mD3d11Module == NULL || mDxgiModule == NULL) |
| 119 | { |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 120 | ERR("Could not load D3D11 or DXGI library - aborting!\n"); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 121 | return EGL_NOT_INITIALIZED; |
| 122 | } |
| 123 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 124 | 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] | 125 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 126 | if (D3D11CreateDevice == NULL) |
| 127 | { |
| 128 | ERR("Could not retrieve D3D11CreateDevice address - aborting!\n"); |
| 129 | return EGL_NOT_INITIALIZED; |
| 130 | } |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 131 | |
| 132 | D3D_FEATURE_LEVEL featureLevel[] = |
| 133 | { |
| 134 | D3D_FEATURE_LEVEL_11_0, |
| 135 | D3D_FEATURE_LEVEL_10_1, |
| 136 | D3D_FEATURE_LEVEL_10_0, |
| 137 | }; |
| 138 | |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 139 | HRESULT result = D3D11CreateDevice(NULL, |
| 140 | D3D_DRIVER_TYPE_HARDWARE, |
| 141 | NULL, |
daniel@transgaming.com | a60160b | 2012-11-28 19:41:15 +0000 | [diff] [blame] | 142 | #if defined(_DEBUG) |
| 143 | D3D11_CREATE_DEVICE_DEBUG, |
| 144 | #else |
| 145 | 0, |
| 146 | #endif |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 147 | featureLevel, |
| 148 | sizeof(featureLevel)/sizeof(featureLevel[0]), |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 149 | D3D11_SDK_VERSION, |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 150 | &mDevice, |
| 151 | &mFeatureLevel, |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 152 | &mDeviceContext); |
daniel@transgaming.com | 25072f6 | 2012-11-28 19:31:32 +0000 | [diff] [blame] | 153 | |
| 154 | if (!mDevice || FAILED(result)) |
daniel@transgaming.com | c1e2634 | 2012-11-28 19:31:16 +0000 | [diff] [blame] | 155 | { |
| 156 | ERR("Could not create D3D11 device - aborting!\n"); |
| 157 | return EGL_NOT_INITIALIZED; // Cleanup done by destructor through glDestroyRenderer |
| 158 | } |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 159 | |
| 160 | IDXGIDevice *dxgiDevice = NULL; |
| 161 | result = mDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice); |
| 162 | |
| 163 | if (FAILED(result)) |
| 164 | { |
| 165 | ERR("Could not query DXGI device - aborting!\n"); |
| 166 | return EGL_NOT_INITIALIZED; |
| 167 | } |
| 168 | |
| 169 | result = dxgiDevice->GetParent(__uuidof(IDXGIAdapter), (void**)&mDxgiAdapter); |
| 170 | |
| 171 | if (FAILED(result)) |
| 172 | { |
| 173 | ERR("Could not retrieve DXGI adapter - aborting!\n"); |
| 174 | return EGL_NOT_INITIALIZED; |
| 175 | } |
| 176 | |
| 177 | dxgiDevice->Release(); |
| 178 | |
daniel@transgaming.com | 1f811f5 | 2012-11-28 20:57:39 +0000 | [diff] [blame] | 179 | mDxgiAdapter->GetDesc(&mAdapterDescription); |
| 180 | memset(mDescription, 0, sizeof(mDescription)); |
| 181 | wcstombs(mDescription, mAdapterDescription.Description, sizeof(mDescription) - 1); |
| 182 | |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 183 | result = mDxgiAdapter->GetParent(__uuidof(IDXGIFactory), (void**)&mDxgiFactory); |
| 184 | |
| 185 | if (!mDxgiFactory || FAILED(result)) |
| 186 | { |
| 187 | ERR("Could not create DXGI factory - aborting!\n"); |
| 188 | return EGL_NOT_INITIALIZED; |
| 189 | } |
| 190 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 191 | initializeDevice(); |
| 192 | |
| 193 | return EGL_SUCCESS; |
| 194 | } |
| 195 | |
| 196 | // do any one-time device initialization |
| 197 | // NOTE: this is also needed after a device lost/reset |
| 198 | // to reset the scene status and ensure the default states are reset. |
| 199 | void Renderer11::initializeDevice() |
| 200 | { |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 201 | mStateCache.initialize(mDevice); |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 202 | mInputLayoutCache.initialize(mDevice, mDeviceContext); |
| 203 | |
| 204 | ASSERT(!mVertexDataManager && !mIndexDataManager); |
| 205 | mVertexDataManager = new VertexDataManager(this); |
| 206 | mIndexDataManager = new IndexDataManager(this); |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 207 | |
daniel@transgaming.com | c43a605 | 2012-11-28 19:41:51 +0000 | [diff] [blame] | 208 | markAllStateDirty(); |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 209 | } |
| 210 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 211 | int Renderer11::generateConfigs(ConfigDesc **configDescList) |
| 212 | { |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 213 | unsigned int numRenderFormats = sizeof(RenderTargetFormats) / sizeof(RenderTargetFormats[0]); |
| 214 | unsigned int numDepthFormats = sizeof(DepthStencilFormats) / sizeof(DepthStencilFormats[0]); |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 215 | (*configDescList) = new ConfigDesc[numRenderFormats * numDepthFormats]; |
| 216 | int numConfigs = 0; |
| 217 | |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 218 | for (unsigned int formatIndex = 0; formatIndex < numRenderFormats; formatIndex++) |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 219 | { |
daniel@transgaming.com | e3e826d | 2012-11-28 19:42:35 +0000 | [diff] [blame] | 220 | for (unsigned int depthStencilIndex = 0; depthStencilIndex < numDepthFormats; depthStencilIndex++) |
daniel@transgaming.com | 65e6537 | 2012-11-28 19:33:50 +0000 | [diff] [blame] | 221 | { |
| 222 | DXGI_FORMAT renderTargetFormat = RenderTargetFormats[formatIndex]; |
| 223 | |
| 224 | UINT formatSupport = 0; |
| 225 | HRESULT result = mDevice->CheckFormatSupport(renderTargetFormat, &formatSupport); |
| 226 | |
| 227 | if (SUCCEEDED(result) && (formatSupport & D3D11_FORMAT_SUPPORT_RENDER_TARGET)) |
| 228 | { |
| 229 | DXGI_FORMAT depthStencilFormat = DepthStencilFormats[depthStencilIndex]; |
| 230 | |
| 231 | UINT formatSupport = 0; |
| 232 | HRESULT result = mDevice->CheckFormatSupport(depthStencilFormat, &formatSupport); |
| 233 | |
| 234 | if (SUCCEEDED(result) && (formatSupport & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL)) |
| 235 | { |
| 236 | ConfigDesc newConfig; |
| 237 | newConfig.renderTargetFormat = d3d11_gl::ConvertBackBufferFormat(renderTargetFormat); |
| 238 | newConfig.depthStencilFormat = d3d11_gl::ConvertDepthStencilFormat(depthStencilFormat); |
| 239 | newConfig.multiSample = 0; // FIXME: enumerate multi-sampling |
| 240 | newConfig.fastConfig = true; // Assume all DX11 format conversions to be fast |
| 241 | |
| 242 | (*configDescList)[numConfigs++] = newConfig; |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | return numConfigs; |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | void Renderer11::deleteConfigs(ConfigDesc *configDescList) |
| 252 | { |
| 253 | delete [] (configDescList); |
| 254 | } |
| 255 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 256 | void Renderer11::sync(bool block) |
| 257 | { |
| 258 | // TODO |
| 259 | UNIMPLEMENTED(); |
| 260 | } |
| 261 | |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 262 | SwapChain *Renderer11::createSwapChain(HWND window, HANDLE shareHandle, GLenum backBufferFormat, GLenum depthBufferFormat) |
| 263 | { |
daniel@transgaming.com | a60160b | 2012-11-28 19:41:15 +0000 | [diff] [blame] | 264 | return new rx::SwapChain11(this, window, shareHandle, backBufferFormat, depthBufferFormat); |
daniel@transgaming.com | b9bb279 | 2012-11-28 19:36:49 +0000 | [diff] [blame] | 265 | } |
| 266 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 267 | void Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::SamplerState &samplerState) |
| 268 | { |
| 269 | // TODO |
| 270 | UNIMPLEMENTED(); |
| 271 | } |
| 272 | |
| 273 | void Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *texture) |
| 274 | { |
| 275 | // TODO |
| 276 | UNIMPLEMENTED(); |
| 277 | } |
| 278 | |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 279 | void Renderer11::setRasterizerState(const gl::RasterizerState &rasterState) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 280 | { |
daniel@transgaming.com | 237bc7e | 2012-11-28 21:01:06 +0000 | [diff] [blame] | 281 | if (mForceSetRasterState || memcmp(&rasterState, &mCurRasterState, sizeof(gl::RasterizerState)) != 0) |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 282 | { |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 283 | ID3D11RasterizerState *dxRasterState = mStateCache.getRasterizerState(rasterState, mScissorEnabled, |
| 284 | mCurDepthSize); |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 285 | if (!dxRasterState) |
| 286 | { |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 287 | ERR("NULL blend state returned by RenderStateCache::getRasterizerState, setting the default" |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 288 | "rasterizer state."); |
| 289 | } |
| 290 | |
| 291 | mDeviceContext->RSSetState(dxRasterState); |
| 292 | |
| 293 | if (dxRasterState) |
| 294 | { |
| 295 | dxRasterState->Release(); |
| 296 | } |
| 297 | mCurRasterState = rasterState; |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | mForceSetRasterState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | void Renderer11::setBlendState(const gl::BlendState &blendState, const gl::Color &blendColor, |
| 304 | unsigned int sampleMask) |
| 305 | { |
daniel@transgaming.com | f8ba109 | 2012-11-28 19:37:53 +0000 | [diff] [blame] | 306 | if (mForceSetBlendState || |
| 307 | memcmp(&blendState, &mCurBlendState, sizeof(gl::BlendState)) != 0 || |
| 308 | memcmp(&blendColor, &mCurBlendColor, sizeof(gl::Color)) != 0 || |
| 309 | sampleMask != mCurSampleMask) |
| 310 | { |
| 311 | ID3D11BlendState *dxBlendState = mStateCache.getBlendState(blendState); |
| 312 | if (!dxBlendState) |
| 313 | { |
| 314 | ERR("NULL blend state returned by RenderStateCache::getBlendState, setting the default " |
| 315 | "blend state."); |
| 316 | } |
| 317 | |
| 318 | const float blendColors[] = { blendColor.red, blendColor.green, blendColor.blue, blendColor.alpha }; |
| 319 | mDeviceContext->OMSetBlendState(dxBlendState, blendColors, sampleMask); |
| 320 | |
| 321 | if (dxBlendState) |
| 322 | { |
| 323 | dxBlendState->Release(); |
| 324 | } |
| 325 | mCurBlendState = blendState; |
| 326 | mCurBlendColor = blendColor; |
| 327 | mCurSampleMask = sampleMask; |
| 328 | } |
| 329 | |
| 330 | mForceSetBlendState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 331 | } |
| 332 | |
daniel@transgaming.com | 08c331d | 2012-11-28 19:38:39 +0000 | [diff] [blame] | 333 | void Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilState, int stencilRef, |
daniel@transgaming.com | 3a0ef48 | 2012-11-28 21:01:20 +0000 | [diff] [blame] | 334 | int stencilBackRef, bool frontFaceCCW) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 335 | { |
daniel@transgaming.com | 5503fd0 | 2012-11-28 19:38:57 +0000 | [diff] [blame] | 336 | if (mForceSetDepthStencilState || |
| 337 | memcmp(&depthStencilState, &mCurDepthStencilState, sizeof(gl::DepthStencilState)) != 0 || |
| 338 | stencilRef != mCurStencilRef || stencilBackRef != mCurStencilBackRef) |
| 339 | { |
| 340 | if (depthStencilState.stencilWritemask != depthStencilState.stencilBackWritemask || |
| 341 | stencilRef != stencilBackRef || |
| 342 | depthStencilState.stencilMask != depthStencilState.stencilBackMask) |
| 343 | { |
| 344 | ERR("Separate front/back stencil writemasks, reference values, or stencil mask values are " |
| 345 | "invalid under WebGL."); |
| 346 | return error(GL_INVALID_OPERATION); |
| 347 | } |
| 348 | |
| 349 | ID3D11DepthStencilState *dxDepthStencilState = mStateCache.getDepthStencilState(depthStencilState); |
| 350 | if (!dxDepthStencilState) |
| 351 | { |
| 352 | ERR("NULL depth stencil state returned by RenderStateCache::getDepthStencilState, " |
| 353 | "setting the default depth stencil state."); |
| 354 | } |
| 355 | |
| 356 | mDeviceContext->OMSetDepthStencilState(dxDepthStencilState, static_cast<UINT>(stencilRef)); |
| 357 | |
| 358 | if (dxDepthStencilState) |
| 359 | { |
| 360 | dxDepthStencilState->Release(); |
| 361 | } |
| 362 | mCurDepthStencilState = depthStencilState; |
| 363 | mCurStencilRef = stencilRef; |
| 364 | mCurStencilBackRef = stencilBackRef; |
| 365 | } |
| 366 | |
| 367 | mForceSetDepthStencilState = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 368 | } |
| 369 | |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 370 | void Renderer11::setScissorRectangle(const gl::Rectangle &scissor, bool enabled) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 371 | { |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 372 | if (mForceSetScissor || memcmp(&scissor, &mCurScissor, sizeof(gl::Rectangle)) != 0 || |
| 373 | enabled != mScissorEnabled) |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 374 | { |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 375 | if (enabled) |
| 376 | { |
| 377 | D3D11_RECT rect; |
| 378 | rect.left = gl::clamp(scissor.x, 0, static_cast<int>(mRenderTargetDesc.width)); |
| 379 | rect.top = gl::clamp(scissor.y, 0, static_cast<int>(mRenderTargetDesc.height)); |
| 380 | rect.right = gl::clamp(scissor.x + scissor.width, 0, static_cast<int>(mRenderTargetDesc.width)); |
| 381 | 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] | 382 | |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 383 | mDeviceContext->RSSetScissorRects(1, &rect); |
| 384 | } |
| 385 | |
| 386 | if (enabled != mScissorEnabled) |
| 387 | { |
| 388 | mForceSetRasterState = true; |
| 389 | } |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 390 | |
| 391 | mCurScissor = scissor; |
daniel@transgaming.com | d55e8c1 | 2012-11-28 21:07:02 +0000 | [diff] [blame] | 392 | mScissorEnabled = enabled; |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | mForceSetScissor = false; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 396 | } |
| 397 | |
daniel@transgaming.com | 1298518 | 2012-12-20 20:56:31 +0000 | [diff] [blame] | 398 | bool Renderer11::setViewport(const gl::Rectangle &viewport, float zNear, float zFar, GLenum drawMode, GLenum frontFace, |
| 399 | bool ignoreViewport, gl::ProgramBinary *currentProgram, bool forceSetUniforms) |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 400 | { |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 401 | gl::Rectangle actualViewport = viewport; |
| 402 | float actualZNear = gl::clamp01(zNear); |
| 403 | float actualZFar = gl::clamp01(zFar); |
| 404 | if (ignoreViewport) |
| 405 | { |
| 406 | actualViewport.x = 0; |
| 407 | actualViewport.y = 0; |
| 408 | actualViewport.width = mRenderTargetDesc.width; |
| 409 | actualViewport.height = mRenderTargetDesc.height; |
| 410 | actualZNear = 0.0f; |
| 411 | actualZFar = 1.0f; |
| 412 | } |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 413 | |
| 414 | D3D11_VIEWPORT dxViewport; |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 415 | dxViewport.TopLeftX = gl::clamp(actualViewport.x, 0, static_cast<int>(mRenderTargetDesc.width)); |
| 416 | dxViewport.TopLeftY = gl::clamp(actualViewport.y, 0, static_cast<int>(mRenderTargetDesc.height)); |
| 417 | dxViewport.Width = gl::clamp(actualViewport.width, 0, static_cast<int>(mRenderTargetDesc.width) - static_cast<int>(dxViewport.TopLeftX)); |
| 418 | dxViewport.Height = gl::clamp(actualViewport.height, 0, static_cast<int>(mRenderTargetDesc.height) - static_cast<int>(dxViewport.TopLeftY)); |
| 419 | dxViewport.MinDepth = actualZNear; |
| 420 | dxViewport.MaxDepth = actualZFar; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 421 | |
| 422 | if (dxViewport.Width <= 0 || dxViewport.Height <= 0) |
| 423 | { |
| 424 | return false; // Nothing to render |
| 425 | } |
| 426 | |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 427 | bool viewportChanged = mForceSetViewport || memcmp(&actualViewport, &mCurViewport, sizeof(gl::Rectangle)) != 0 || |
| 428 | actualZNear != mCurNear || actualZFar != mCurFar; |
| 429 | |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 430 | if (viewportChanged) |
| 431 | { |
| 432 | mDeviceContext->RSSetViewports(1, &dxViewport); |
| 433 | |
daniel@transgaming.com | 4c4ce23 | 2012-11-28 21:01:40 +0000 | [diff] [blame] | 434 | mCurViewport = actualViewport; |
| 435 | mCurNear = actualZNear; |
| 436 | mCurFar = actualZFar; |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | if (currentProgram && (viewportChanged || forceSetUniforms)) |
| 440 | { |
daniel@transgaming.com | 88853c5 | 2012-12-20 20:56:40 +0000 | [diff] [blame] | 441 | currentProgram->applyDxHalfPixelSize(0.0f, 0.0f); |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 442 | |
| 443 | // These values are used for computing gl_FragCoord in Program::linkVaryings(). |
daniel@transgaming.com | 88853c5 | 2012-12-20 20:56:40 +0000 | [diff] [blame] | 444 | currentProgram->applyDxCoord(actualViewport.width * 0.5f, |
| 445 | actualViewport.height * 0.5f, |
| 446 | actualViewport.x + (actualViewport.width * 0.5f), |
| 447 | actualViewport.y + (actualViewport.height * 0.5f)); |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 448 | |
daniel@transgaming.com | 1298518 | 2012-12-20 20:56:31 +0000 | [diff] [blame] | 449 | 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] | 450 | currentProgram->applyDxDepthFront((actualZFar - actualZNear) * 0.5f, (actualZNear + actualZFar) * 0.5f, ccw); |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 451 | |
daniel@transgaming.com | 88853c5 | 2012-12-20 20:56:40 +0000 | [diff] [blame] | 452 | currentProgram->applyDxDepthRange(actualZNear, actualZFar, actualZFar - actualZNear); |
daniel@transgaming.com | 5367004 | 2012-11-28 20:55:51 +0000 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | mForceSetViewport = false; |
daniel@transgaming.com | 83e80ee | 2012-11-28 19:40:53 +0000 | [diff] [blame] | 456 | return true; |
| 457 | } |
| 458 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 459 | bool Renderer11::applyPrimitiveType(GLenum mode, GLsizei count) |
| 460 | { |
daniel@transgaming.com | c52be63 | 2012-11-28 21:04:28 +0000 | [diff] [blame] | 461 | D3D11_PRIMITIVE_TOPOLOGY primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_UNDEFINED; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 462 | |
daniel@transgaming.com | 0b03b06 | 2012-11-28 21:03:49 +0000 | [diff] [blame] | 463 | switch (mode) |
| 464 | { |
daniel@transgaming.com | c52be63 | 2012-11-28 21:04:28 +0000 | [diff] [blame] | 465 | case GL_POINTS: primitiveTopology = D3D11_PRIMITIVE_TOPOLOGY_POINTLIST; break; |
| 466 | case GL_LINES: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_LINELIST; break; |
daniel@transgaming.com | 0b03b06 | 2012-11-28 21:03:49 +0000 | [diff] [blame] | 467 | case GL_LINE_LOOP: UNIMPLEMENTED(); /* TODO */ break; |
daniel@transgaming.com | c52be63 | 2012-11-28 21:04:28 +0000 | [diff] [blame] | 468 | case GL_LINE_STRIP: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_LINESTRIP; break; |
| 469 | case GL_TRIANGLES: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; break; |
| 470 | case GL_TRIANGLE_STRIP: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP; break; |
daniel@transgaming.com | 0b03b06 | 2012-11-28 21:03:49 +0000 | [diff] [blame] | 471 | case GL_TRIANGLE_FAN: UNIMPLEMENTED(); /* TODO */ break; |
| 472 | default: |
| 473 | return error(GL_INVALID_ENUM, false); |
| 474 | } |
| 475 | |
daniel@transgaming.com | c52be63 | 2012-11-28 21:04:28 +0000 | [diff] [blame] | 476 | mDeviceContext->IASetPrimitiveTopology(primitiveTopology); |
daniel@transgaming.com | 0b03b06 | 2012-11-28 21:03:49 +0000 | [diff] [blame] | 477 | |
| 478 | return count > 0; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | bool Renderer11::applyRenderTarget(gl::Framebuffer *framebuffer) |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 482 | { |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 483 | // Get the color render buffer and serial |
| 484 | gl::Renderbuffer *renderbufferObject = NULL; |
| 485 | unsigned int renderTargetSerial = 0; |
| 486 | if (framebuffer->getColorbufferType() != GL_NONE) |
| 487 | { |
| 488 | renderbufferObject = framebuffer->getColorbuffer(); |
daniel@transgaming.com | dcf1e67 | 2012-11-28 19:38:19 +0000 | [diff] [blame] | 489 | |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 490 | if (!renderbufferObject) |
| 491 | { |
| 492 | ERR("render target pointer unexpectedly null."); |
daniel@transgaming.com | e9c71b4 | 2012-11-28 21:02:23 +0000 | [diff] [blame] | 493 | return false; |
daniel@transgaming.com | 80fc332 | 2012-11-28 21:02:13 +0000 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | renderTargetSerial = renderbufferObject->getSerial(); |
| 497 | } |
| 498 | |
| 499 | // Get the depth stencil render buffer and serials |
| 500 | gl::Renderbuffer *depthStencil = NULL; |
| 501 | unsigned int depthbufferSerial = 0; |
| 502 | unsigned int stencilbufferSerial = 0; |
| 503 | if (framebuffer->getDepthbufferType() != GL_NONE) |
| 504 | { |
| 505 | depthStencil = framebuffer->getDepthbuffer(); |
| 506 | if (!depthStencil) |
| 507 | { |
| 508 | ERR("Depth stencil pointer unexpectedly null."); |
| 509 | return false; |
| 510 | } |
| 511 | |
| 512 | depthbufferSerial = depthStencil->getSerial(); |
| 513 | } |
| 514 | else if (framebuffer->getStencilbufferType() != GL_NONE) |
| 515 | { |
| 516 | depthStencil = framebuffer->getStencilbuffer(); |
| 517 | if (!depthStencil) |
| 518 | { |
| 519 | ERR("Depth stencil pointer unexpectedly null."); |
| 520 | return false; |
| 521 | } |
| 522 | |
| 523 | stencilbufferSerial = depthStencil->getSerial(); |
| 524 | } |
| 525 | |
| 526 | // Extract the render target dimensions and view |
| 527 | unsigned int renderTargetWidth = 0; |
| 528 | unsigned int renderTargetHeight = 0; |
| 529 | GLenum renderTargetFormat = 0; |
| 530 | ID3D11RenderTargetView* framebufferRTV = NULL; |
| 531 | if (renderbufferObject) |
| 532 | { |
| 533 | RenderTarget11 *renderTarget = RenderTarget11::makeRenderTarget11(renderbufferObject->getRenderTarget()); |
| 534 | if (!renderTarget) |
| 535 | { |
| 536 | ERR("render target pointer unexpectedly null."); |
| 537 | return false; |
| 538 | } |
| 539 | |
| 540 | framebufferRTV = renderTarget->getRenderTargetView(); |
| 541 | if (!framebufferRTV) |
| 542 | { |
| 543 | ERR("render target view pointer unexpectedly null."); |
| 544 | return false; |
| 545 | } |
| 546 | |
| 547 | renderTargetWidth = renderbufferObject->getWidth(); |
| 548 | renderTargetHeight = renderbufferObject->getHeight(); |
| 549 | renderTargetFormat = renderbufferObject->getActualFormat(); |
| 550 | } |
| 551 | |
| 552 | // Extract the depth stencil sizes and view |
| 553 | unsigned int depthSize = 0; |
| 554 | unsigned int stencilSize = 0; |
| 555 | ID3D11DepthStencilView* framebufferDSV = NULL; |
| 556 | if (depthStencil) |
| 557 | { |
| 558 | RenderTarget11 *depthStencilRenderTarget = RenderTarget11::makeRenderTarget11(depthStencil->getDepthStencil()); |
| 559 | if (!depthStencilRenderTarget) |
| 560 | { |
| 561 | ERR("render target pointer unexpectedly null."); |
| 562 | if (framebufferRTV) |
| 563 | { |
| 564 | framebufferRTV->Release(); |
| 565 | } |
| 566 | return false; |
| 567 | } |
| 568 | |
| 569 | framebufferDSV = depthStencilRenderTarget->getDepthStencilView(); |
| 570 | if (!framebufferDSV) |
| 571 | { |
| 572 | ERR("depth stencil view pointer unexpectedly null."); |
| 573 | if (framebufferRTV) |
| 574 | { |
| 575 | framebufferRTV->Release(); |
| 576 | } |
| 577 | return false; |
| 578 | } |
| 579 | |
| 580 | // If there is no render buffer, the width, height and format values come from |
| 581 | // the depth stencil |
| 582 | if (!renderbufferObject) |
| 583 | { |
| 584 | renderTargetWidth = depthStencil->getWidth(); |
| 585 | renderTargetHeight = depthStencil->getHeight(); |
| 586 | renderTargetFormat = depthStencil->getActualFormat(); |
| 587 | } |
| 588 | |
| 589 | depthSize = depthStencil->getDepthSize(); |
| 590 | stencilSize = depthStencil->getStencilSize(); |
| 591 | } |
| 592 | |
| 593 | // Apply the render target and depth stencil |
| 594 | if (!mRenderTargetDescInitialized || !mDepthStencilInitialized || |
| 595 | renderTargetSerial != mAppliedRenderTargetSerial || |
| 596 | depthbufferSerial != mAppliedDepthbufferSerial || |
| 597 | stencilbufferSerial != mAppliedStencilbufferSerial) |
| 598 | { |
| 599 | mDeviceContext->OMSetRenderTargets(1, &framebufferRTV, framebufferDSV); |
| 600 | |
| 601 | mRenderTargetDesc.width = renderTargetWidth; |
| 602 | mRenderTargetDesc.height = renderTargetHeight; |
| 603 | mRenderTargetDesc.format = renderTargetFormat; |
| 604 | mForceSetViewport = true; // TODO: It may not be required to clamp the viewport in D3D11 |
| 605 | mForceSetScissor = true; // TODO: It may not be required to clamp the scissor in D3D11 |
| 606 | |
| 607 | if (!mDepthStencilInitialized || depthSize != mCurDepthSize) |
| 608 | { |
| 609 | mCurDepthSize = depthSize; |
| 610 | mForceSetRasterState = true; |
| 611 | } |
| 612 | |
| 613 | mCurStencilSize = stencilSize; |
| 614 | |
| 615 | mAppliedRenderTargetSerial = renderTargetSerial; |
| 616 | mAppliedDepthbufferSerial = depthbufferSerial; |
| 617 | mAppliedStencilbufferSerial = stencilbufferSerial; |
| 618 | mRenderTargetDescInitialized = true; |
| 619 | mDepthStencilInitialized = true; |
| 620 | } |
| 621 | |
| 622 | if (framebufferRTV) |
| 623 | { |
| 624 | framebufferRTV->Release(); |
| 625 | } |
| 626 | if (framebufferDSV) |
| 627 | { |
| 628 | framebufferDSV->Release(); |
| 629 | } |
daniel@transgaming.com | ae39ee2 | 2012-11-28 19:42:02 +0000 | [diff] [blame] | 630 | |
| 631 | return true; |
daniel@transgaming.com | 493d4f8 | 2012-11-28 19:35:45 +0000 | [diff] [blame] | 632 | } |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 633 | |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 634 | 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] | 635 | { |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 636 | TranslatedAttribute attributes[gl::MAX_VERTEX_ATTRIBS]; |
| 637 | GLenum err = mVertexDataManager->prepareVertexData(vertexAttributes, programBinary, first, count, attributes, instances); |
| 638 | if (err != GL_NO_ERROR) |
daniel@transgaming.com | da495a1 | 2012-11-28 21:03:56 +0000 | [diff] [blame] | 639 | { |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 640 | return err; |
| 641 | } |
daniel@transgaming.com | da495a1 | 2012-11-28 21:03:56 +0000 | [diff] [blame] | 642 | |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 643 | return mInputLayoutCache.applyVertexBuffers(attributes, programBinary); |
daniel@transgaming.com | def9f0f | 2012-11-28 20:53:20 +0000 | [diff] [blame] | 644 | } |
| 645 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 646 | 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] | 647 | { |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 648 | GLenum err = mIndexDataManager->prepareIndexData(type, count, elementArrayBuffer, indices, indexInfo); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 649 | |
daniel@transgaming.com | c5431eb | 2012-12-20 21:10:15 +0000 | [diff] [blame] | 650 | if (err == GL_NO_ERROR) |
| 651 | { |
| 652 | if (indexInfo->serial != mAppliedIBSerial) |
| 653 | { |
| 654 | IndexBuffer11* indexBuffer = IndexBuffer11::makeIndexBuffer11(indexInfo->indexBuffer); |
| 655 | |
| 656 | mDeviceContext->IASetIndexBuffer(indexBuffer->getBuffer(), indexBuffer->getIndexFormat(), indexInfo->startIndex); |
| 657 | mAppliedIBSerial = indexInfo->serial; |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | return err; |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | void Renderer11::drawArrays(GLenum mode, GLsizei count, GLsizei instances) |
| 665 | { |
daniel@transgaming.com | d4cf251 | 2012-11-28 21:05:41 +0000 | [diff] [blame] | 666 | mDeviceContext->Draw(count, 0); |
daniel@transgaming.com | 91207b7 | 2012-11-28 20:56:43 +0000 | [diff] [blame] | 667 | } |
| 668 | |
daniel@transgaming.com | 3124048 | 2012-11-28 21:06:41 +0000 | [diff] [blame] | 669 | 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] | 670 | { |
daniel@transgaming.com | c511430 | 2012-12-20 21:11:36 +0000 | [diff] [blame] | 671 | if (mode == GL_LINE_LOOP) |
| 672 | { |
| 673 | drawLineLoop(count, type, indices, indexInfo.minIndex, elementArrayBuffer); |
| 674 | } |
| 675 | else |
| 676 | { |
| 677 | mDeviceContext->DrawIndexed(indexInfo.maxIndex - indexInfo.minIndex + 1, 0, -static_cast<int>(indexInfo.minIndex)); |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | void Renderer11::drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer) |
| 682 | { |
| 683 | // Get the raw indices for an indexed draw |
| 684 | if (type != GL_NONE && elementArrayBuffer) |
| 685 | { |
| 686 | gl::Buffer *indexBuffer = elementArrayBuffer; |
| 687 | intptr_t offset = reinterpret_cast<intptr_t>(indices); |
| 688 | indices = static_cast<const GLubyte*>(indexBuffer->data()) + offset; |
| 689 | } |
| 690 | |
| 691 | if (!mLineLoopIB) |
| 692 | { |
| 693 | mLineLoopIB = new StreamingIndexBufferInterface(this); |
| 694 | if (!mLineLoopIB->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_INT)) |
| 695 | { |
| 696 | delete mLineLoopIB; |
| 697 | mLineLoopIB = NULL; |
| 698 | |
| 699 | ERR("Could not create a 32-bit looping index buffer for GL_LINE_LOOP."); |
| 700 | return error(GL_OUT_OF_MEMORY); |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | const int spaceNeeded = (count + 1) * sizeof(unsigned int); |
| 705 | if (!mLineLoopIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_INT)) |
| 706 | { |
| 707 | ERR("Could not reserve enough space in looping index buffer for GL_LINE_LOOP."); |
| 708 | return error(GL_OUT_OF_MEMORY); |
| 709 | } |
| 710 | |
| 711 | void* mappedMemory = NULL; |
| 712 | int offset = mLineLoopIB->mapBuffer(spaceNeeded, &mappedMemory); |
| 713 | if (offset == -1 || mappedMemory == NULL) |
| 714 | { |
| 715 | ERR("Could not map index buffer for GL_LINE_LOOP."); |
| 716 | return error(GL_OUT_OF_MEMORY); |
| 717 | } |
| 718 | |
| 719 | UINT startIndex = static_cast<UINT>(offset) / 4; |
| 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 | |
| 765 | mDeviceContext->IASetIndexBuffer(indexBuffer->getBuffer(), indexBuffer->getIndexFormat(), startIndex); |
| 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 | { |
| 1300 | // TODO |
| 1301 | UNIMPLEMENTED(); |
| 1302 | return false; |
| 1303 | } |
| 1304 | |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 1305 | bool Renderer11::copyToRenderTarget(TextureStorageInterfaceCube *dest, TextureStorageInterfaceCube *source) |
daniel@transgaming.com | ad6aee7 | 2012-11-28 19:33:42 +0000 | [diff] [blame] | 1306 | { |
| 1307 | // TODO |
| 1308 | UNIMPLEMENTED(); |
| 1309 | return false; |
| 1310 | } |
| 1311 | |
daniel@transgaming.com | 3838088 | 2012-11-28 19:36:39 +0000 | [diff] [blame] | 1312 | bool Renderer11::copyImage(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 1313 | GLint xoffset, GLint yoffset, TextureStorageInterface2D *storage, GLint level) |
daniel@transgaming.com | 3838088 | 2012-11-28 19:36:39 +0000 | [diff] [blame] | 1314 | { |
| 1315 | // TODO |
| 1316 | UNIMPLEMENTED(); |
| 1317 | return false; |
| 1318 | } |
| 1319 | |
| 1320 | bool Renderer11::copyImage(gl::Framebuffer *framebuffer, const RECT &sourceRect, GLenum destFormat, |
daniel@transgaming.com | 87705f8 | 2012-12-20 21:10:45 +0000 | [diff] [blame] | 1321 | GLint xoffset, GLint yoffset, TextureStorageInterfaceCube *storage, GLenum target, GLint level) |
daniel@transgaming.com | 3838088 | 2012-11-28 19:36:39 +0000 | [diff] [blame] | 1322 | { |
| 1323 | // TODO |
| 1324 | UNIMPLEMENTED(); |
| 1325 | return false; |
| 1326 | } |
| 1327 | |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 1328 | RenderTarget *Renderer11::createRenderTarget(SwapChain *swapChain, bool depth) |
| 1329 | { |
daniel@transgaming.com | b6b27bc | 2012-11-28 20:54:30 +0000 | [diff] [blame] | 1330 | SwapChain11 *swapChain11 = SwapChain11::makeSwapChain11(swapChain); |
| 1331 | RenderTarget11 *renderTarget = NULL; |
| 1332 | if (depth) |
| 1333 | { |
| 1334 | renderTarget = new RenderTarget11(this, swapChain11->getDepthStencil(), swapChain11->getWidth(), swapChain11->getHeight()); |
| 1335 | } |
| 1336 | else |
| 1337 | { |
| 1338 | renderTarget = new RenderTarget11(this, swapChain11->getRenderTarget(), swapChain11->getWidth(), swapChain11->getHeight()); |
| 1339 | } |
| 1340 | return renderTarget; |
daniel@transgaming.com | f242365 | 2012-11-28 20:53:50 +0000 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | RenderTarget *Renderer11::createRenderTarget(int width, int height, GLenum format, GLsizei samples, bool depth) |
| 1344 | { |
| 1345 | // TODO |
| 1346 | UNIMPLEMENTED(); |
| 1347 | return NULL; |
| 1348 | } |
| 1349 | |
daniel@transgaming.com | 2275f91 | 2012-12-20 21:13:22 +0000 | [diff] [blame] | 1350 | ShaderExecutable *Renderer11::loadExecutable(const void *function, size_t length, GLenum type) |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 1351 | { |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 1352 | ShaderExecutable11 *executable = NULL; |
| 1353 | |
| 1354 | switch (type) |
| 1355 | { |
| 1356 | case GL_VERTEX_SHADER: |
| 1357 | { |
| 1358 | ID3D11VertexShader *vshader = NULL; |
| 1359 | HRESULT result = mDevice->CreateVertexShader(function, length, NULL, &vshader); |
| 1360 | ASSERT(SUCCEEDED(result)); |
| 1361 | |
| 1362 | if (vshader) |
| 1363 | { |
daniel@transgaming.com | 7b18d0c | 2012-11-28 21:04:10 +0000 | [diff] [blame] | 1364 | executable = new ShaderExecutable11(function, length, vshader); |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 1365 | } |
| 1366 | } |
| 1367 | break; |
| 1368 | case GL_FRAGMENT_SHADER: |
| 1369 | { |
| 1370 | ID3D11PixelShader *pshader = NULL; |
| 1371 | HRESULT result = mDevice->CreatePixelShader(function, length, NULL, &pshader); |
| 1372 | ASSERT(SUCCEEDED(result)); |
| 1373 | |
| 1374 | if (pshader) |
| 1375 | { |
daniel@transgaming.com | 7b18d0c | 2012-11-28 21:04:10 +0000 | [diff] [blame] | 1376 | executable = new ShaderExecutable11(function, length, pshader); |
daniel@transgaming.com | a2f9fbe | 2012-11-28 21:03:40 +0000 | [diff] [blame] | 1377 | } |
| 1378 | } |
| 1379 | break; |
| 1380 | default: |
| 1381 | UNREACHABLE(); |
| 1382 | break; |
| 1383 | } |
| 1384 | |
| 1385 | return executable; |
daniel@transgaming.com | 5531890 | 2012-11-28 20:58:58 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
daniel@transgaming.com | a9c7142 | 2012-11-28 20:58:45 +0000 | [diff] [blame] | 1388 | ShaderExecutable *Renderer11::compileToExecutable(gl::InfoLog &infoLog, const char *shaderHLSL, GLenum type) |
| 1389 | { |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 1390 | const char *profile = NULL; |
| 1391 | |
| 1392 | switch (type) |
| 1393 | { |
| 1394 | case GL_VERTEX_SHADER: |
| 1395 | profile = "vs_4_0"; |
| 1396 | break; |
| 1397 | case GL_FRAGMENT_SHADER: |
| 1398 | profile = "ps_4_0"; |
| 1399 | break; |
| 1400 | default: |
| 1401 | UNREACHABLE(); |
| 1402 | return NULL; |
| 1403 | } |
| 1404 | |
daniel@transgaming.com | 25e16af | 2012-11-28 21:05:57 +0000 | [diff] [blame] | 1405 | ID3DBlob *binary = compileToBinary(infoLog, shaderHLSL, profile, false); |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 1406 | if (!binary) |
| 1407 | return NULL; |
| 1408 | |
daniel@transgaming.com | 2275f91 | 2012-12-20 21:13:22 +0000 | [diff] [blame] | 1409 | ShaderExecutable *executable = loadExecutable((DWORD *)binary->GetBufferPointer(), binary->GetBufferSize(), type); |
daniel@transgaming.com | 071ee6a | 2012-11-28 21:03:21 +0000 | [diff] [blame] | 1410 | binary->Release(); |
| 1411 | |
| 1412 | return executable; |
| 1413 | } |
| 1414 | |
daniel@transgaming.com | 3f255b4 | 2012-12-20 21:07:35 +0000 | [diff] [blame] | 1415 | VertexBuffer *Renderer11::createVertexBuffer() |
| 1416 | { |
daniel@transgaming.com | 2c4d070 | 2012-12-20 21:08:51 +0000 | [diff] [blame] | 1417 | return new VertexBuffer11(this); |
daniel@transgaming.com | 3f255b4 | 2012-12-20 21:07:35 +0000 | [diff] [blame] | 1418 | } |
| 1419 | |
daniel@transgaming.com | 0b6d774 | 2012-12-20 21:09:47 +0000 | [diff] [blame] | 1420 | IndexBuffer *Renderer11::createIndexBuffer() |
| 1421 | { |
daniel@transgaming.com | 11c2af5 | 2012-12-20 21:10:01 +0000 | [diff] [blame] | 1422 | return new IndexBuffer11(this); |
daniel@transgaming.com | 0b6d774 | 2012-12-20 21:09:47 +0000 | [diff] [blame] | 1423 | } |
| 1424 | |
daniel@transgaming.com | 6c87217 | 2012-11-28 19:39:33 +0000 | [diff] [blame] | 1425 | bool Renderer11::blitRect(gl::Framebuffer *readTarget, gl::Rectangle *readRect, gl::Framebuffer *drawTarget, gl::Rectangle *drawRect, |
| 1426 | bool blitRenderTarget, bool blitDepthStencil) |
| 1427 | { |
| 1428 | // TODO |
| 1429 | UNIMPLEMENTED(); |
| 1430 | return false; |
| 1431 | } |
| 1432 | |
| 1433 | void Renderer11::readPixels(gl::Framebuffer *framebuffer, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, |
| 1434 | GLsizei outputPitch, bool packReverseRowOrder, GLint packAlignment, void* pixels) |
| 1435 | { |
| 1436 | // TODO |
| 1437 | UNIMPLEMENTED(); |
| 1438 | return; |
| 1439 | } |
| 1440 | |
daniel@transgaming.com | 244e183 | 2012-12-20 20:52:35 +0000 | [diff] [blame] | 1441 | Image *Renderer11::createImage() |
| 1442 | { |
daniel@transgaming.com | a8aac67 | 2012-12-20 21:08:00 +0000 | [diff] [blame] | 1443 | return new Image11(); |
daniel@transgaming.com | 244e183 | 2012-12-20 20:52:35 +0000 | [diff] [blame] | 1444 | } |
| 1445 | |
daniel@transgaming.com | f721fdb | 2012-12-20 20:53:11 +0000 | [diff] [blame] | 1446 | void Renderer11::generateMipmap(Image *dest, Image *src) |
| 1447 | { |
| 1448 | // TODO |
| 1449 | UNIMPLEMENTED(); |
| 1450 | return; |
| 1451 | } |
| 1452 | |
daniel@transgaming.com | 413d271 | 2012-12-20 21:11:04 +0000 | [diff] [blame] | 1453 | TextureStorage *Renderer11::createTextureStorage2D(SwapChain *swapChain) |
| 1454 | { |
| 1455 | // TODO |
| 1456 | UNIMPLEMENTED(); |
| 1457 | return NULL; |
| 1458 | } |
| 1459 | |
| 1460 | TextureStorage *Renderer11::createTextureStorage2D(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, GLsizei width, GLsizei height) |
| 1461 | { |
| 1462 | // TODO |
| 1463 | UNIMPLEMENTED(); |
| 1464 | return NULL; |
| 1465 | } |
| 1466 | |
| 1467 | TextureStorage *Renderer11::createTextureStorageCube(int levels, GLenum internalformat, GLenum usage, bool forceRenderable, int size) |
| 1468 | { |
| 1469 | // TODO |
| 1470 | UNIMPLEMENTED(); |
| 1471 | return NULL; |
| 1472 | } |
| 1473 | |
daniel@transgaming.com | 1d6aff2 | 2012-11-28 19:30:42 +0000 | [diff] [blame] | 1474 | } |