Здравствуйте, Aleksey Skurihin, Вы писали:
8>>Я у себя практически ваш код запустил, все в порядке. Делал stretch поверхности 640x480 на 990x730.
8>>в оконном режиме 60фпс (частота обновления экрана, т.е все как и должно быть), загрузка ~10%
AS>можете прислать Ваш код?
bool cDXRender::Open(const wchar_t *inWindowTitle, int inWidth, int inHeight, bool inFullScreen, tWndProc inWindowProcedure)
{
Close();
windowProcedure = inWindowProcedure;
fullScreen = inFullScreen;
width = inWidth;
height = inHeight;
midleWidth = width/2;
midleHeight = height/2;
instance = GetModuleHandle(NULL);
WNDCLASS wc;
int style1;
int style2;
wc.style = CS_OWNDC;
wc.lpfnWndProc = (WNDPROC)WindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = (HINSTANCE)instance;
wc.hIcon = LoadIcon((HINSTANCE)instance, MAKEINTRESOURCE(IDI_APPLICATION));
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.hbrBackground = 0;
wc.lpszMenuName = 0;
wc.lpszClassName = L"dx9render wc";
if (!RegisterClass(&wc))
{
return (false);
}
int winPosX = 0;
int winPosY = 0;
if (fullScreen)
{
style2 = WS_EX_TOPMOST;
style1 = WS_POPUP | WS_VISIBLE;
}
else
{
winPosX = (GetSystemMetrics(SM_CXSCREEN) - inWidth)/2;
winPosY = (GetSystemMetrics(SM_CYSCREEN) - inHeight)/2;
style2 = 0;
style1 = WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_VISIBLE;
}
wnd = CreateWindowEx(
style2,
L"dx9render wc",
(LPCTSTR)inWindowTitle,
style1,
winPosX, winPosY, inWidth, inHeight,
NULL,
NULL,
instance,
NULL);
if (!wnd)
{
return (false);
}
SetWindowLong(wnd, GWL_USERDATA, (long)this);
ShowWindow(wnd, SW_NORMAL);
if ((d3d = Direct3DCreate9(D3D_SDK_VERSION)) == NULL)
{
return (false);
}
#define MULTITHREADED_D3D
#ifdef MULTITHREADED_D3D
# define _D3DDEV_FLAGS (D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED)
#else
# define _D3DDEV_FLAGS (D3DCREATE_SOFTWARE_VERTEXPROCESSING)
#endif
D3DPRESENT_PARAMETERS d3dpp;
memset(&d3dpp, 0, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.hDeviceWindow = wnd;
if(D3D_OK !=
d3d->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
wnd,
_D3DDEV_FLAGS,
&d3dpp,
&device
)
)
{
return (false);
}
return true;
}
int APIENTRY WinMain(HINSTANCE inInstance, HINSTANCE inPrevInstance, LPSTR inCmdLine, int inCmdShow)
{
HRESULT hr;
cDXRender r;
DWORD time = GetTickCount();
DWORD stime = GetTickCount();
DWORD tmil;
int frames = 0;
int fps = 0;
r.Open(L"asd", 1600, 1000, false, 0);
IDirect3DDevice9 *d3d_dev_ = r.device;
IDirect3DSurface9* surface_;
hr = d3d_dev_->CreateOffscreenPlainSurface(
640,
480,
(D3DFORMAT)D3DFMT_A8R8G8B8,
D3DPOOL_DEFAULT,
&surface_,
0
);
while (true)
{
MSG wmsg;
if (PeekMessage((LPMSG)&wmsg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage((LPMSG)&wmsg);
DispatchMessage((LPMSG)&wmsg);
}
D3DLOCKED_RECT lockedRect;
if (surface_->LockRect(&lockedRect, 0, D3DLOCK_DISCARD) != D3D_OK)
{
return -1;
}
for (int i = 0; i < 200; ++i)
{
memset((char*)lockedRect.pBits+lockedRect.Pitch*i, 127, lockedRect.Pitch);
}
surface_->UnlockRect();
d3d_dev_->Clear( 0, NULL, D3DCLEAR_TARGET, 0, 1.0f, 0 );
d3d_dev_->BeginScene();
frames++;
DWORD ctime = GetTickCount();
tmil = ctime - stime;
DWORD dtime = ctime-time;
time = ctime;
//d3d_dev_->SetFVF(D3DFVF_CUSTOMVERTEX);
// d3d_dev_->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
d3d_dev_->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
d3d_dev_->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA);
d3d_dev_->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
// device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
IDirect3DSurface9* backBuf = 0;
if (d3d_dev_->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuf) != D3D_OK)
{
return -1;
}
//IDirect3DSurface9* backBuf;
//d3d_dev_->GetRenderTarget(0,&backBuf);
RECT aSrcRect;
aSrcRect.left = 0;
aSrcRect.right = 320;
aSrcRect.top = 0;
aSrcRect.bottom = 200;
RECT aDestRect;
aDestRect.left = 0;
aDestRect.right = 1590;
aDestRect.top = 0;
aDestRect.bottom = 960;
hr = d3d_dev_->StretchRect(surface_, &aSrcRect, backBuf, &aDestRect, D3DTEXF_LINEAR);
if(D3D_OK != hr)
{
hr = d3d_dev_->StretchRect(surface_, &aSrcRect, backBuf, &aDestRect, D3DTEXF_NONE);
if(D3D_OK != hr)
{
return -1;
}
}
backBuf->Release();
if (tmil > 2000)
{
fps = (int)((float)frames/((float)tmil/1000.0f));
stime = GetTickCount();
frames = 0;
}
//r.DrawFps(fps);
d3d_dev_->EndScene();
{
HRESULT hr = d3d_dev_->Present( NULL, NULL, NULL, NULL );
}
}
}
AS>или один но разрешение 1600 на 1000.
Все в порядке. ~57 фпс