CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/GPU/Directx9/FramebufferManagerDX9.cpp
Views: 1401
// Copyright (c) 2012- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#include <d3d9.h>1819#include "Common/Common.h"20#include "Common/GPU/thin3d.h"2122#include "GPU/Common/FramebufferManagerCommon.h"23#include "GPU/Common/GPUStateUtils.h"24#include "GPU/Common/PresentationCommon.h"25#include "GPU/Common/TextureDecoder.h"26#include "GPU/Directx9/FramebufferManagerDX9.h"2728FramebufferManagerDX9::FramebufferManagerDX9(Draw::DrawContext *draw)29: FramebufferManagerCommon(draw) {30presentation_->SetLanguage(HLSL_D3D9);31preferredPixelsFormat_ = Draw::DataFormat::B8G8R8A8_UNORM;32}3334bool FramebufferManagerDX9::ReadbackDepthbuffer(Draw::Framebuffer *fbo, int x, int y, int w, int h, uint16_t *pixels, int pixelsStride, int destW, int destH, Draw::ReadbackMode mode) {35// Don't yet support stretched readbacks here.36if (destW != w || destH != h) {37return false;38}3940// We always read the depth buffer in 24_8 format.41LPDIRECT3DTEXTURE9 tex = (LPDIRECT3DTEXTURE9)draw_->GetFramebufferAPITexture(fbo, Draw::FB_DEPTH_BIT, 0);42if (!tex)43return false;4445// This is separate from the thin3d way because it applies DepthScaleFactors.46D3DSURFACE_DESC desc;47D3DLOCKED_RECT locked;48tex->GetLevelDesc(0, &desc);4950RECT rect = {(LONG)x, (LONG)y, (LONG)w, (LONG)h};51HRESULT hr = tex->LockRect(0, &locked, &rect, D3DLOCK_READONLY);52if (!SUCCEEDED(hr))53return false;5455const u32 *packed = (const u32 *)locked.pBits;56u16 *depth = (u16 *)pixels;5758DepthScaleFactors depthScale = GetDepthScaleFactors(gstate_c.UseFlags());59// TODO: Optimize.60for (int yp = 0; yp < h; ++yp) {61for (int xp = 0; xp < w; ++xp) {62const int offset = (yp + y) * pixelsStride + x + xp;6364float scaled = depthScale.DecodeToU16((packed[offset] & 0x00FFFFFF) * (1.0f / 16777215.0f));65if (scaled <= 0.0f) {66depth[offset] = 0;67} else if (scaled >= 65535.0f) {68depth[offset] = 65535;69} else {70depth[offset] = (int)scaled;71}72}73}7475tex->UnlockRect(0);76return true;77}787980