Sign in to follow this  
clowkun

window lags when moved off the screen

Recommended Posts

clowkun    122
Hello, I am working on a small game in DirectX 10 the June 2007 SDK and the game renders just fine but when I move the window out of the screen and move it back, it takes a second for the game to re-draw the texture or if I minimize the window and then refocus the window it takes a second or two to get everything back on the screen. Why does this happen? Is there any way to right my code in a more efficient way so to avoid this? Here is a small class for a texture that is being drawn to the screen, so if you see anything in it that looks like a resource hog please let me know.
#include "GameTexture.h"

GameTexture::GameTexture(float w, float h)
{
	width = w;
	height = h;
	visible = true;
}

GameTexture::~GameTexture()
{
}

int GameTexture::GetTexture2DFromFile(ID3D10Device* gameDevice, LPCWSTR filename)
{
	// loads the texture into ID3D10Resource object
	HRESULT hr = D3DX10CreateTextureFromFile(gameDevice, (LPCWSTR)filename, NULL, NULL, &pResource, NULL);

	// make sure the texture was loaded in successfully
	if (FAILED(hr))
	{
		return 1;
	}

	// translates the ID3D10Resource object into a ID3D10Texture2D object
	hr = pResource->QueryInterface(__uuidof( ID3D10Texture2D), (LPVOID*)&texture);
	if (FAILED(hr))
	{
		return 1;
	}

	pResource->Release();

	// end of function
	return 0;
}

void GameTexture::GetTextureDesc()
{
	
	desc.Width = (size_t)width;
	desc.Height = (size_t)height;
	desc.MipLevels = 1;
	desc.ArraySize = 1;
	desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
	desc.SampleDesc.Count = 1;
	desc.Usage = D3D10_USAGE_DEFAULT;
	desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
	
	// get description structure
	texture->GetDesc(&desc);
}

int GameTexture::Render(ID3D10Device* gameDevice, IDXGISwapChain* gameSwap, float width, float height)
{
	// get a pointer to the back buffer for the texture
	HRESULT hr = gameSwap->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&pBackBuffer);

	if (hr != S_OK)
	{
		return 1;
	}
	
	GetTextureDesc();

	D3D10_BOX sourceRegion;
	sourceRegion.left = 0;
	sourceRegion.right = (int)width;
	sourceRegion.top = 0;
	sourceRegion.bottom = (int)height;
	sourceRegion.front = 0;
	sourceRegion.back = 1;

	// copy part of a texture resource to the back buffer texture
	// the last parameter is a D3D10_BOX structure which defines the rectangle too 
	// copy to the back buffer
	gameDevice->CopySubresourceRegion(pBackBuffer, 0, 0, 0, 0, texture, 0, &sourceRegion);

	// end of function
	return 0;
}

float GameTexture::getHeight()
{
	return height;
}

float GameTexture::getWidth()
{
	return width;
}

bool GameTexture::isVisible()
{
	return visible;
}

void GameTexture::setVisible(bool b)
{
	visible = b;
}
Thank you for your help in advance.

Share this post


Link to post
Share on other sites
Erik Rufelt    5901
Firstly, why are you using such an old version of the SDK, especially when using D3D10 which is still pretty new?
I would recommend downloading the August 2009 SDK, and the latest drivers from the manufacturer's homepage for your graphics card. If you still have the problem after, then why are you using CopySubresourceRegion, instead of drawing a quad or something?
I also don't understand why you fill in the desc structure in GetTextureDesc and then call texture->GetDesc, which will overwrite anything you put in it. I see you have a 128-bit format in there.. is your texture of this format?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this