PDA

View Full Version : Troubles with the mipmap chain



chronozphere
11-02-2007, 07:32 PM
Hi fellow pascal coders. :)

I'm having a problem with the following code:


//create sysmem texture
HR := D3DXCreateTexture(Graphic.fD3DDevice,fWidth,fHeigh t,1,0,fmt,D3DPOOL_SYSTEMMEM,fSysTex);
if Failed(HR) then
begin
Result := E_TEX_CREATE_FAILED;
LastErrorDX(Result,HR);
Exit;
end;

{lock texture and transfer data from fBitmap to fTexture}
HR := fSysTex.GetSurfaceLevel(0,Surf);
if Failed(HR) then
begin
Result := E_TEX_SURFACE_FAILED;
LastErrorDX(Result,HR);
Exit;
end;

//lock entire surface
HR := Surf.LockRect(D3DRect,nil,D3DLOCK_NOSYSLOCK);
if Failed(HR) then
begin
Result := E_TEX_LOCK_FAILED;
LastErrorDX(Result,HR);
Exit;
end;

//set alpha channel so every texel is visible
for i:=0 to fbitmap.Height-1 do
for j:=0 to fBitmap.Width-1 do
(PChar(fBitmap.ScanLine[i])+(j*4)+3)^ := Char(255);

{move the data from fBitmap to fTexture}
for i:=0 to fBitmap.Height-1 do
Move((fBitmap.Scanline[i])^,(PChar(D3DRect.pBits)+(D3DRect.pitch*i))^,fBitm ap.Width*PXSize);

Surf.UnlockRect;

//update texture to VRAM
HR := Graphic.fD3DDevice.UpdateTexture(fsysTex,fTexture) ;
if Failed(HR) then
begin
Result := E_TEX_UPDATE_FAILED;
LastErrorDX(Result,HR);
Exit;
end;
Surf := nil;


As many of you allready understand, this code moves data from a bitmap to the allready existing texture called fTexture wich is created in D3DPOOL_DEFAULT. The problem is that the mipmap chain of fTexture doesn't (or at least not good) get updated.

When i look at the texture from a sharp angle, the updated part isn't fully rendered anymore. :(

So what have i done:
I've loaded a bitmap with the texture and i've created a texture in D3DPOOL_DEFAULT from this bitmap data.
No i've drawn a red rectangle onto the bitmap and i want to update it to video memory. And that's what the above shown code does.

I'll show you some images.

http://www.techzine.nl/f/g/36261phpZP0uLs.jpg
http://www.techzine.nl/f/g/36261php3PT7rt.jpg
{even when looking with a 90 degree angle to the texture, doesn't make it have a solid red color :( }

As you can see, the red rectangle dissapears when looking from a sharp angle. I guess it has something to do with mipmapping. The changes (red rectangle) are somehow not fully applied on the whole mipmap chain.

Can anyone explain me what i'm doing wrong. :?

Any help would be greatly appreciated ;)

chronozphere
12-02-2007, 07:19 PM
YAY :D :thumbup: I think i've found the sollution and it feels great... aha.. aha.. etc.

But ofcourse i'm gonna share my sollution with you:

if you ever want to apply changes on a mipmapped texture. Just lock the first (zero) surface and do your stuff. When the first surface is updated, use the following D3DX routine to apply the changes to the lower surfaces in the mipmap chain:


D3DXFilterTexture(fMyTexture,nil,0,D3DX_FILTER_LIN EAR);


You can specify other filtering parameters if you want. :)

This routine wil use surface 0, to update the rest of the mipmap chain. It even fiters the pixeldata... :P

Happy mipmapping ;)