Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

StretchRect problem

1,076 views
Skip to first unread message

no_name

unread,
Oct 29, 2008, 9:29:59 AM10/29/08
to
I'm trying to scale down a surface with the code below (please ignore memory
leaks etc... )
The line with StretchRect() method fails with code D3DERR_INVALIDCALL.
All suggestions/comments are welcome.

m_pDirect3D9 = Direct3DCreate9(D3D_SDK_VERSION);

if(m_pDirect3D9){

IDirect3DDevice9* pDirect3DDevice;
D3DPRESENT_PARAMETERS params = { 0 };

params.BackBufferWidth = 0;
params.BackBufferHeight = 0;
params.BackBufferFormat = D3DFMT_UNKNOWN;
params.BackBufferCount = 1;
params.MultiSampleType = D3DMULTISAMPLE_NONE;
params.MultiSampleQuality = 0;
params.SwapEffect = D3DSWAPEFFECT_DISCARD;
params.Windowed = TRUE;
params.hDeviceWindow = hWnd;
params.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
params.EnableAutoDepthStencil = FALSE;
params.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;

hr = m_pDirect3D9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
NULL, D3DCREATE_MIXED_VERTEXPROCESSING, &params, &pDirect3DDevice);

if(SUCCEEDED(hr)){
IDirect3DSurface9* psurface1;

hr = pDirect3DDevice->CreateOffscreenPlainSurface(720, 576,
D3DFMT_UYVY, D3DPOOL_DEFAULT, &psurface1, NULL);

if(SUCCEEDED(hr)){

IDirect3DSurface9* psurface2;
D3DLOCKED_RECT lockedRect;

hr = psurface1->LockRect(&lockedRect, NULL,
D3DLOCK_DISCARD);

if(SUCCEEDED(hr)){
BYTE* pBuff = (BYTE*)lockedRect.pBits;
for(int y = 0; y < 576; ++y){
ZeroMemory(pBuff + y * lockedRect.Pitch, 720 * 2);
}
hr = psurface1->UnlockRect();
}

hr = pDirect3DDevice->CreateOffscreenPlainSurface(540, 432,
D3DFMT_UYVY, D3DPOOL_DEFAULT, &psurface2, NULL);

if(SUCCEEDED(hr)){
hr = pDirect3DDevice->StretchRect(psurface1, NULL, psurface2,
NULL, D3DTEXF_LINEAR);
DXTRACE_ERR(TEXT("DX ERROR: "),hr);
}
}
}

DXTRACE_ERR(TEXT("DX ERROR: "),hr);


Armin Zingler

unread,
Oct 29, 2008, 10:30:58 AM10/29/08
to
"no_name" <send_...@microsoft.com> schrieb

> I'm trying to scale down a surface with the code below (please
> ignore memory leaks etc... )
> The line with StretchRect() method fails with code
> D3DERR_INVALIDCALL. All suggestions/comments are welcome.

Debug runtime chosen? Native debugging enabled?

My output window says:
"Direct3D9: (ERROR) :Unable to stretch from an offscreen plain to another
offscreen plain. StretchRect failed"

> if(SUCCEEDED(hr)){
> hr = pDirect3DDevice->StretchRect(psurface1, NULL, psurface2,
> NULL, D3DTEXF_LINEAR);
> DXTRACE_ERR(TEXT("DX ERROR: "),hr);
> }

See the bottom most table, bottom right cell in the documentation on
StretchRect:
http://msdn.microsoft.com/en-us/library/bb174471(VS.85).aspx

It says streching from and to an off-screen plain surface is not supported.

I currently have no other solution handy.


Armin

no_name

unread,
Oct 29, 2008, 11:02:44 AM10/29/08
to

"Armin Zingler" <az.n...@freenet.de> wrote in message
news:uCrWLYdO...@TK2MSFTNGP03.phx.gbl...

> "no_name" <send_...@microsoft.com> schrieb
>> I'm trying to scale down a surface with the code below (please
>> ignore memory leaks etc... )
>> The line with StretchRect() method fails with code
>> D3DERR_INVALIDCALL. All suggestions/comments are welcome.
>
> Debug runtime chosen? Native debugging enabled?
>
> My output window says:
> "Direct3D9: (ERROR) :Unable to stretch from an offscreen plain to another
> offscreen plain. StretchRect failed"
>
>> if(SUCCEEDED(hr)){
>> hr = pDirect3DDevice->StretchRect(psurface1, NULL, psurface2,
>> NULL, D3DTEXF_LINEAR);
>> DXTRACE_ERR(TEXT("DX ERROR: "),hr);
>> }
>

I have release runtime.
I was looking only my MSDN (March 2008) which says:

Stretching is not supported if the destination surface is an off-screen
plain surface but the source is not.

> See the bottom most table, bottom right cell in the documentation on
> StretchRect:
> http://msdn.microsoft.com/en-us/library/bb174471(VS.85).aspx
>
> It says streching from and to an off-screen plain surface is not
> supported.

Yes, this version of MSDN says it's not possible what I wanted to do.

>
> I currently have no other solution handy.
>

Any other idea on scaling UYVY image undex DirectX?


Richard [Microsoft Direct3D MVP]

unread,
Oct 29, 2008, 6:34:13 PM10/29/08
to
[Please do not mail me a copy of your followup]

"no_name" <send_...@microsoft.com> spake the secret code
<#aXacddO...@TK2MSFTNGP05.phx.gbl> thusly:

>I have release runtime.

Install the SDK, switch to the debug runtime through the supplied
utility and then pay attention to the debug stream output when your
program is run. Developing Direct3D applications without the debug
runtime is like running through a mine field.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://www.xmission.com/~legalize/book/download/index.html>

Legalize Adulthood! <http://blogs.xmission.com/legalize/>

no_name

unread,
Oct 30, 2008, 5:39:15 AM10/30/08
to

"Richard [Microsoft Direct3D MVP]" <legaliz...@mail.xmission.com> wrote
in message news:uUAK5Zh...@TK2MSFTNGP06.phx.gbl...

> [Please do not mail me a copy of your followup]
>
> "no_name" <send_...@microsoft.com> spake the secret code
> <#aXacddO...@TK2MSFTNGP05.phx.gbl> thusly:
>
>>I have release runtime.
>
> Install the SDK, switch to the debug runtime through the supplied
> utility and then pay attention to the debug stream output when your
> program is run. Developing Direct3D applications without the debug
> runtime is like running through a mine field.

I'll do that. But at the moment I have no idea how to solve the scaling.
Perhaps to forget the whole Direct3D story and use my own implementation of
bilinear scaling.


smartx

unread,
Oct 30, 2008, 6:30:03 PM10/30/08
to

Hi, you can not use stretchrect() with ( src:offscreen, dst:offscreen
plain )
there is some restrictions in using this function also a difference
between dx8 driver and dx9 driver, but I will show you dx9 version:

it can be used like the follows:
if there is no stretching:

texture render target ----> texture render target.
texture render target ----> render target surface
off-screen plain ---> texture surface
off-screen plain ---> texture render target
off-screen plain ---> render target surface
off-screen plain ---> off-screen plain
other combination that are not specified are not allowed.

if there is a stretching:

texture surface ---> texture render target surface.
texture surface ---> render target surface ( like frame buffer )
texture render target ----> texture render target.
texture render target ----> render target surface
render target surface ----> texture render target
render target surface ----> render target surface
off-screen plain surface -----> texture render target
off-screen plain surface -----> render target surface
other combinations that are not specified are not allowed.

Best regards,
smart,
http://gptutors.com

Tim Roberts

unread,
Oct 31, 2008, 2:28:13 AM10/31/08
to
"no_name" <send_...@microsoft.com> wrote:
>
>I'll do that. But at the moment I have no idea how to solve the scaling.
>Perhaps to forget the whole Direct3D story and use my own implementation of
>bilinear scaling.

Yes. That is the only path that is going to lead to success. You are
simply never going to find a system service to do scaling of in-memory YUV
surfaces.
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

no_name

unread,
Oct 31, 2008, 8:59:45 AM10/31/08
to
Thank you very much!!
That's excellent info!!!!


0 new messages