diff options
Diffstat (limited to '3rdparty/bgfx/src/renderer_d3d9.cpp')
-rw-r--r-- | 3rdparty/bgfx/src/renderer_d3d9.cpp | 105 |
1 files changed, 75 insertions, 30 deletions
diff --git a/3rdparty/bgfx/src/renderer_d3d9.cpp b/3rdparty/bgfx/src/renderer_d3d9.cpp index 58e45db9032..4f4267be9ad 100644 --- a/3rdparty/bgfx/src/renderer_d3d9.cpp +++ b/3rdparty/bgfx/src/renderer_d3d9.cpp @@ -329,13 +329,13 @@ namespace bgfx { namespace d3d9 ErrorState::Enum errorState = ErrorState::Default; m_fbh.idx = invalidHandle; - memset(m_uniforms, 0, sizeof(m_uniforms) ); - memset(&m_resolution, 0, sizeof(m_resolution) ); + bx::memSet(m_uniforms, 0, sizeof(m_uniforms) ); + bx::memSet(&m_resolution, 0, sizeof(m_resolution) ); D3DFORMAT adapterFormat = D3DFMT_X8R8G8B8; // http://msdn.microsoft.com/en-us/library/windows/desktop/bb172588%28v=vs.85%29.aspx - memset(&m_params, 0, sizeof(m_params) ); + bx::memSet(&m_params, 0, sizeof(m_params) ); m_params.BackBufferWidth = BGFX_DEFAULT_WIDTH; m_params.BackBufferHeight = BGFX_DEFAULT_HEIGHT; m_params.BackBufferFormat = adapterFormat; @@ -1023,7 +1023,7 @@ namespace bgfx { namespace d3d9 for (uint32_t yy = 0, height = srcHeight; yy < height; ++yy) { - memcpy(dst, src, pitch); + bx::memCopy(dst, src, pitch); src += srcPitch; dst += dstPitch; @@ -1117,7 +1117,7 @@ namespace bgfx { namespace d3d9 uint32_t size = BX_ALIGN_16(g_uniformTypeSize[_type]*_num); void* data = BX_ALLOC(g_allocator, size); - memset(data, 0, size); + bx::memSet(data, 0, size); m_uniforms[_handle.idx] = data; m_uniformReg.add(_handle, _name, data); } @@ -1129,9 +1129,23 @@ namespace bgfx { namespace d3d9 m_uniformReg.remove(_handle); } - void saveScreenShot(const char* _filePath) BX_OVERRIDE + void requestScreenShot(FrameBufferHandle _handle, const char* _filePath) BX_OVERRIDE { #if BX_PLATFORM_WINDOWS + IDirect3DSwapChain9* swapChain = isValid(_handle) + ? m_frameBuffers[_handle.idx].m_swapChain + : m_swapChain + ; + + if (NULL == swapChain) + { + BX_TRACE("Unable to capture screenshot %s.", _filePath); + return; + } + + D3DPRESENT_PARAMETERS params; + DX_CHECK(swapChain->GetPresentParameters(¶ms)); + IDirect3DSurface9* surface; D3DDEVICE_CREATION_PARAMETERS dcp; DX_CHECK(m_device->GetCreationParameters(&dcp) ); @@ -1147,8 +1161,14 @@ namespace bgfx { namespace d3d9 , NULL ) ); + HWND nwh = params.hDeviceWindow; + + SetWindowPos(nwh, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); + DX_CHECK(m_device->GetFrontBufferData(0, surface) ); + SetWindowPos(nwh, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); + D3DLOCKED_RECT rect; DX_CHECK(surface->LockRect(&rect , NULL @@ -1156,25 +1176,27 @@ namespace bgfx { namespace d3d9 ) ); RECT rc; - GetClientRect( (HWND)g_platformData.nwh, &rc); + GetClientRect(nwh, &rc); POINT point; point.x = rc.left; point.y = rc.top; - ClientToScreen( (HWND)g_platformData.nwh, &point); + ClientToScreen(nwh, &point); uint8_t* data = (uint8_t*)rect.pBits; uint32_t bytesPerPixel = rect.Pitch/dm.Width; g_callback->screenShot(_filePath - , m_params.BackBufferWidth - , m_params.BackBufferHeight + , params.BackBufferWidth + , params.BackBufferHeight , rect.Pitch , &data[point.y*rect.Pitch+point.x*bytesPerPixel] - , m_params.BackBufferHeight*rect.Pitch + , params.BackBufferHeight*rect.Pitch , false ); DX_CHECK(surface->UnlockRect() ); DX_RELEASE(surface, 0); +#else + BX_UNUSED(_handle, _filePath); #endif // BX_PLATFORM_WINDOWS } @@ -1196,7 +1218,7 @@ namespace bgfx { namespace d3d9 void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) BX_OVERRIDE { - memcpy(m_uniforms[_loc], _data, _size); + bx::memCopy(m_uniforms[_loc], _data, _size); } void setMarker(const char* _marker, uint32_t _size) BX_OVERRIDE @@ -1210,6 +1232,11 @@ namespace bgfx { namespace d3d9 BX_UNUSED(_marker, _size); } + void invalidateOcclusionQuery(OcclusionQueryHandle _handle) BX_OVERRIDE + { + m_occlusionQuery.invalidate(_handle); + } + void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) BX_OVERRIDE; void blitSetup(TextVideoMemBlitter& _blitter) BX_OVERRIDE @@ -1760,7 +1787,7 @@ namespace bgfx { namespace d3d9 else { UniformHandle handle; - memcpy(&handle, _uniformBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) ); + bx::memCopy(&handle, _uniformBuffer.read(sizeof(UniformHandle) ), sizeof(UniformHandle) ); data = (const char*)m_uniforms[handle.idx]; } @@ -2004,7 +2031,7 @@ namespace bgfx { namespace d3d9 for (uint32_t ii = 0; ii < numMrt; ++ii) { uint8_t index = (uint8_t)bx::uint32_min(BGFX_CONFIG_MAX_COLOR_PALETTE - 1, _clear.m_index[ii]); - memcpy(mrtClear[ii], _palette[index], 16); + bx::memCopy(mrtClear[ii], _palette[index], 16); } } else @@ -2019,7 +2046,7 @@ namespace bgfx { namespace d3d9 for (uint32_t ii = 0; ii < numMrt; ++ii) { - memcpy(mrtClear[ii], rgba, 16); + bx::memCopy(mrtClear[ii], rgba, 16); } } @@ -2311,7 +2338,7 @@ namespace bgfx { namespace d3d9 bool asInt; _decl.decode(Attrib::Enum(attr), num, type, normalized, asInt); - memcpy(elem, &s_attrib[attr], sizeof(D3DVERTEXELEMENT9) ); + bx::memCopy(elem, &s_attrib[attr], sizeof(D3DVERTEXELEMENT9) ); elem->Type = s_attribType[type][num-1][normalized]; elem->Offset = _decl.m_offset[attr]; @@ -2331,13 +2358,13 @@ namespace bgfx { namespace d3d9 for (uint8_t ii = 0; ii < _numInstanceData; ++ii) { - memcpy(elem, &inst, sizeof(D3DVERTEXELEMENT9) ); + bx::memCopy(elem, &inst, sizeof(D3DVERTEXELEMENT9) ); elem->UsageIndex = uint8_t(7-ii); // TEXCOORD7 = i_data0, TEXCOORD6 = i_data1, etc. elem->Offset = ii*16; ++elem; } - memcpy(elem, &s_attrib[Attrib::Count], sizeof(D3DVERTEXELEMENT9) ); + bx::memCopy(elem, &s_attrib[Attrib::Count], sizeof(D3DVERTEXELEMENT9) ); IDirect3DVertexDeclaration9* ptr; DX_CHECK(s_renderD3D9->m_device->CreateVertexDeclaration(vertexElements, &ptr) ); @@ -2346,7 +2373,7 @@ namespace bgfx { namespace d3d9 void VertexDeclD3D9::create(const VertexDecl& _decl) { - memcpy(&m_decl, &_decl, sizeof(VertexDecl) ); + bx::memCopy(&m_decl, &_decl, sizeof(VertexDecl) ); dump(m_decl); m_ptr = createVertexDeclaration(_decl, 0); } @@ -2990,7 +3017,7 @@ namespace bgfx { namespace d3d9 break; default: - memcpy(bits, mip.m_data, size); + bx::memCopy(bits, mip.m_data, size); break; } } @@ -3052,7 +3079,7 @@ namespace bgfx { namespace d3d9 break; default: - memcpy(dst, src, rectpitch); + bx::memCopy(dst, src, rectpitch); break; } src += srcpitch; @@ -3159,7 +3186,7 @@ namespace bgfx { namespace d3d9 m_num = 0; m_numTh = _num; m_needResolve = false; - memcpy(m_attachment, _attachment, _num*sizeof(Attachment) ); + bx::memCopy(m_attachment, _attachment, _num*sizeof(Attachment) ); for (uint32_t ii = 0; ii < _num; ++ii) { @@ -3216,7 +3243,7 @@ namespace bgfx { namespace d3d9 m_height = bx::uint32_max(_height, 16); D3DPRESENT_PARAMETERS params; - memcpy(¶ms, &s_renderD3D9->m_params, sizeof(D3DPRESENT_PARAMETERS) ); + bx::memCopy(¶ms, &s_renderD3D9->m_params, sizeof(D3DPRESENT_PARAMETERS) ); params.BackBufferWidth = m_width; params.BackBufferHeight = m_height; @@ -3326,7 +3353,7 @@ namespace bgfx { namespace d3d9 if (NULL != m_hwnd) { D3DPRESENT_PARAMETERS params; - memcpy(¶ms, &s_renderD3D9->m_params, sizeof(D3DPRESENT_PARAMETERS) ); + bx::memCopy(¶ms, &s_renderD3D9->m_params, sizeof(D3DPRESENT_PARAMETERS) ); params.BackBufferWidth = m_width; params.BackBufferHeight = m_height; @@ -3547,18 +3574,36 @@ namespace bgfx { namespace d3d9 { Query& query = m_query[m_control.m_read]; - uint32_t result; - HRESULT hr = query.m_ptr->GetData(&result, sizeof(result), 0); - if (S_FALSE == hr) + if (isValid(query.m_handle) ) { - break; + uint32_t result; + HRESULT hr = query.m_ptr->GetData(&result, sizeof(result), 0); + if (S_FALSE == hr) + { + break; + } + + _render->m_occlusion[query.m_handle.idx] = int32_t(result); } - _render->m_occlusion[query.m_handle.idx] = 0 < result; m_control.consume(1); } } + void OcclusionQueryD3D9::invalidate(OcclusionQueryHandle _handle) + { + const uint32_t size = m_control.m_size; + + for (uint32_t ii = 0, num = m_control.available(); ii < num; ++ii) + { + Query& query = m_query[(m_control.m_read + ii) % size]; + if (query.m_handle.idx == _handle.idx) + { + query.m_handle.idx = bgfx::invalidHandle; + } + } + } + void RendererContextD3D9::submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) { IDirect3DDevice9* device = m_device; @@ -3795,7 +3840,7 @@ namespace bgfx { namespace d3d9 else { Rect scissorRect; - scissorRect.intersect(viewScissorRect, _render->m_rectCache.m_cache[scissor]); + scissorRect.setIntersect(viewScissorRect, _render->m_rectCache.m_cache[scissor]); if (scissorRect.isZeroArea() ) { continue; |