diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index a64083cf9f8..7b7598bbb89 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -811,15 +811,6 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateSurface(IWineD3DDevice *iface, U object->Flags |= (WINED3DFMT_D16_LOCKABLE == Format) ? SFLAG_LOCKABLE : 0; object->Flags |= Lockable ? SFLAG_LOCKABLE : 0; - - if (WINED3DFMT_UNKNOWN != Format) { - object->bytesPerPixel = glDesc->byte_count; - } else { - object->bytesPerPixel = 0; - } - - /** TODO: change this into a texture transform matrix so that it's processed in hardware **/ - TRACE("Pool %d %d %d %d\n",Pool, WINED3DPOOL_DEFAULT, WINED3DPOOL_MANAGED, WINED3DPOOL_SYSTEMMEM); /** Quick lockable sanity check TODO: remove this after surfaces, usage and lockability have been debugged properly @@ -1242,7 +1233,6 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateVolume(IWineD3DDevice *iface, object->currentDesc.Width = Width; object->currentDesc.Height = Height; object->currentDesc.Depth = Depth; - object->bytesPerPixel = format_desc->byte_count; /** Note: Volume textures cannot be dxtn, hence no need to check here **/ object->lockable = TRUE; @@ -6042,7 +6032,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_UpdateSurface(IWineD3DDevice *iface, int offset = 0; int rowoffset = 0; /* how many bytes to add onto the end of a row to wraparound to the beginning of the next */ glDescriptor *glDescription = NULL; - const struct GlPixelFormatDesc *dst_format_desc; + const struct GlPixelFormatDesc *src_format_desc, *dst_format_desc; GLenum dummy; int sampler; int bpp; @@ -6106,6 +6096,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_UpdateSurface(IWineD3DDevice *iface, IWineD3DSurface_GetGlDesc(pDestinationSurface, &glDescription); + src_format_desc = ((IWineD3DSurfaceImpl *)pSrcSurface)->resource.format_desc; dst_format_desc = ((IWineD3DSurfaceImpl *)pDestinationSurface)->resource.format_desc; /* this needs to be done in lines if the sourceRect != the sourceWidth */ @@ -6119,14 +6110,14 @@ static HRESULT WINAPI IWineD3DDeviceImpl_UpdateSurface(IWineD3DDevice *iface, /* This function doesn't support compressed textures the pitch is just bytesPerPixel * width */ if(srcWidth != srcSurfaceWidth || srcLeft ){ - rowoffset = srcSurfaceWidth * pSrcSurface->bytesPerPixel; - offset += srcLeft * pSrcSurface->bytesPerPixel; + rowoffset = srcSurfaceWidth * src_format_desc->byte_count; + offset += srcLeft * src_format_desc->byte_count; /* TODO: do we ever get 3bpp?, would a shift and an add be quicker than a mul (well maybe a cycle or two) */ } /* TODO DXT formats */ if(pSourceRect != NULL && pSourceRect->top != 0){ - offset += pSourceRect->top * srcSurfaceWidth * pSrcSurface->bytesPerPixel; + offset += pSourceRect->top * srcSurfaceWidth * src_format_desc->byte_count; } TRACE("(%p) glTexSubImage2D, level %d, left %d, top %d, width %d, height %d, fmt %#x, type %#x, memory %p+%#x\n", This, glDescription->level, destLeft, destTop, srcWidth, srcHeight, dst_format_desc->glFormat, diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c index 08cf64f6f4b..fc71ecfdcc9 100644 --- a/dlls/wined3d/surface.c +++ b/dlls/wined3d/surface.c @@ -190,7 +190,7 @@ static void surface_download_data(IWineD3DSurfaceImpl *This) { if (This->Flags & SFLAG_NONPOW2) { unsigned char alignment = This->resource.wineD3DDevice->surface_alignment; - src_pitch = This->bytesPerPixel * This->pow2Width; + src_pitch = format_desc->byte_count * This->pow2Width; dst_pitch = IWineD3DSurface_GetPitch((IWineD3DSurface *) This); src_pitch = (src_pitch + alignment - 1) & ~(alignment - 1); mem = HeapAlloc(GetProcessHeap(), 0, src_pitch * This->pow2Height); @@ -811,7 +811,7 @@ static void read_from_framebuffer(IWineD3DSurfaceImpl *This, CONST RECT *rect, v fmt = GL_ALPHA; type = GL_UNSIGNED_BYTE; mem = dest; - bpp = This->bytesPerPixel; + bpp = This->resource.format_desc->byte_count; } else { /* GL can't return palettized data, so read ARGB pixels into a * separate block of memory and convert them into palettized format @@ -831,7 +831,7 @@ static void read_from_framebuffer(IWineD3DSurfaceImpl *This, CONST RECT *rect, v LEAVE_GL(); return; } - bpp = This->bytesPerPixel * 3; + bpp = This->resource.format_desc->byte_count * 3; } } break; @@ -840,7 +840,7 @@ static void read_from_framebuffer(IWineD3DSurfaceImpl *This, CONST RECT *rect, v mem = dest; fmt = This->resource.format_desc->glFormat; type = This->resource.format_desc->glType; - bpp = This->bytesPerPixel; + bpp = This->resource.format_desc->byte_count; } if(This->Flags & SFLAG_PBO) { @@ -1623,7 +1623,7 @@ HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_ *format = glDesc->glFormat; *type = glDesc->glType; *convert = NO_CONVERSION; - *target_bpp = This->bytesPerPixel; + *target_bpp = glDesc->byte_count; if(srgb_mode) { *internal = glDesc->glGammaInternal; diff --git a/dlls/wined3d/surface_base.c b/dlls/wined3d/surface_base.c index 401f98390c9..8d9d941fa0c 100644 --- a/dlls/wined3d/surface_base.c +++ b/dlls/wined3d/surface_base.c @@ -346,7 +346,7 @@ DWORD WINAPI IWineD3DBaseSurfaceImpl_GetPitch(IWineD3DSurface *iface) { ret = ((This->currentDesc.Width + 3) >> 2) << 4; else { unsigned char alignment = This->resource.wineD3DDevice->surface_alignment; - ret = This->bytesPerPixel * This->currentDesc.Width; /* Bytes / row */ + ret = This->resource.format_desc->byte_count * This->currentDesc.Width; /* Bytes / row */ ret = (ret + alignment - 1) & ~(alignment - 1); } TRACE("(%p) Returning %d\n", This, ret); @@ -534,17 +534,11 @@ HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3D This->resource.size *= This->pow2Height; } - if (format != WINED3DFMT_UNKNOWN) { - This->bytesPerPixel = format_desc->byte_count; - } else { - This->bytesPerPixel = 0; - } - This->Flags |= (WINED3DFMT_D16_LOCKABLE == format) ? SFLAG_LOCKABLE : 0; This->resource.format_desc = format_desc; - TRACE("(%p) : Size %d, bytesPerPixel %d\n", This, This->resource.size, This->bytesPerPixel); + TRACE("(%p) : Size %d, bytesPerPixel %d\n", This, This->resource.size, format_desc->byte_count); return WINED3D_OK; } @@ -559,7 +553,8 @@ HRESULT IWineD3DBaseSurfaceImpl_CreateDIBSection(IWineD3DSurface *iface) { DWORD *masks; UINT usage; - switch (This->bytesPerPixel) { + switch (format_desc->byte_count) + { case 2: case 4: /* Allocate extra space to store the RGB bit masks. */ @@ -573,9 +568,7 @@ HRESULT IWineD3DBaseSurfaceImpl_CreateDIBSection(IWineD3DSurface *iface) { default: /* Allocate extra space for a palette. */ b_info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, - sizeof(BITMAPINFOHEADER) - + sizeof(RGBQUAD) - * (1 << (This->bytesPerPixel * 8))); + sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * (1 << (format_desc->byte_count * 8))); break; } @@ -595,11 +588,11 @@ HRESULT IWineD3DBaseSurfaceImpl_CreateDIBSection(IWineD3DSurface *iface) { b_info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); /* TODO: Is there a nicer way to force a specific alignment? (8 byte for ddraw) */ - b_info->bmiHeader.biWidth = IWineD3DSurface_GetPitch(iface) / This->bytesPerPixel; + b_info->bmiHeader.biWidth = IWineD3DSurface_GetPitch(iface) / format_desc->byte_count; b_info->bmiHeader.biHeight = -This->currentDesc.Height -extraline; b_info->bmiHeader.biSizeImage = ( This->currentDesc.Height + extraline) * IWineD3DSurface_GetPitch(iface); b_info->bmiHeader.biPlanes = 1; - b_info->bmiHeader.biBitCount = This->bytesPerPixel * 8; + b_info->bmiHeader.biBitCount = format_desc->byte_count * 8; b_info->bmiHeader.biXPelsPerMeter = 0; b_info->bmiHeader.biYPelsPerMeter = 0; @@ -1138,7 +1131,7 @@ HRESULT WINAPI IWineD3DBaseSurfaceImpl_Blt(IWineD3DSurface *iface, const RECT *D } } - bpp = This->bytesPerPixel; + bpp = This->resource.format_desc->byte_count; srcheight = xsrc.bottom - xsrc.top; srcwidth = xsrc.right - xsrc.left; dstheight = xdst.bottom - xdst.top; @@ -1630,7 +1623,7 @@ HRESULT WINAPI IWineD3DBaseSurfaceImpl_BltFast(IWineD3DSurface *iface, DWORD dst lock_dst.right = dstx + w; lock_dst.bottom = dsty + h; - bpp = This->bytesPerPixel; + bpp = This->resource.format_desc->byte_count; /* We need to lock the surfaces, or we won't get refreshes when done. */ if (Src == This) @@ -1854,7 +1847,7 @@ HRESULT WINAPI IWineD3DBaseSurfaceImpl_LockRect(IWineD3DSurface *iface, WINED3DL { pLockedRect->pBits = This->resource.allocatedMemory + (pLockedRect->Pitch * pRect->top) + - (pRect->left * This->bytesPerPixel); + (pRect->left * This->resource.format_desc->byte_count); } This->lockedRect.left = pRect->left; This->lockedRect.top = pRect->top; diff --git a/dlls/wined3d/surface_gdi.c b/dlls/wined3d/surface_gdi.c index 64b73568c0e..0ed350ecee9 100644 --- a/dlls/wined3d/surface_gdi.c +++ b/dlls/wined3d/surface_gdi.c @@ -333,7 +333,7 @@ const char* filename) } else { int red_shift, green_shift, blue_shift, pix_width, alpha_shift; - pix_width = This->bytesPerPixel; + pix_width = format_desc->byte_count; red_shift = get_shift(format_desc->red_mask); green_shift = get_shift(format_desc->green_mask); diff --git a/dlls/wined3d/volume.c b/dlls/wined3d/volume.c index 8f6ae8d3f35..64d871b83ec 100644 --- a/dlls/wined3d/volume.c +++ b/dlls/wined3d/volume.c @@ -218,8 +218,9 @@ static HRESULT WINAPI IWineD3DVolumeImpl_LockBox(IWineD3DVolume *iface, WINED3DL /* fixme: should we really lock as such? */ TRACE("(%p) : box=%p, output pbox=%p, allMem=%p\n", This, pBox, pLockedVolume, This->resource.allocatedMemory); - pLockedVolume->RowPitch = This->bytesPerPixel * This->currentDesc.Width; /* Bytes / row */ - pLockedVolume->SlicePitch = This->bytesPerPixel * This->currentDesc.Width * This->currentDesc.Height; /* Bytes / slice */ + pLockedVolume->RowPitch = This->resource.format_desc->byte_count * This->currentDesc.Width; /* Bytes / row */ + pLockedVolume->SlicePitch = This->resource.format_desc->byte_count + * This->currentDesc.Width * This->currentDesc.Height; /* Bytes / slice */ if (!pBox) { TRACE("No box supplied - all is ok\n"); pLockedVolume->pBits = This->resource.allocatedMemory; @@ -231,10 +232,10 @@ static HRESULT WINAPI IWineD3DVolumeImpl_LockBox(IWineD3DVolume *iface, WINED3DL This->lockedBox.Back = This->currentDesc.Depth; } else { TRACE("Lock Box (%p) = l %d, t %d, r %d, b %d, fr %d, ba %d\n", pBox, pBox->Left, pBox->Top, pBox->Right, pBox->Bottom, pBox->Front, pBox->Back); - pLockedVolume->pBits = This->resource.allocatedMemory + - (pLockedVolume->SlicePitch * pBox->Front) + /* FIXME: is front < back or vica versa? */ - (pLockedVolume->RowPitch * pBox->Top) + - (pBox->Left * This->bytesPerPixel); + pLockedVolume->pBits = This->resource.allocatedMemory + + (pLockedVolume->SlicePitch * pBox->Front) /* FIXME: is front < back or vica versa? */ + + (pLockedVolume->RowPitch * pBox->Top) + + (pBox->Left * This->resource.format_desc->byte_count); This->lockedBox.Left = pBox->Left; This->lockedBox.Top = pBox->Top; This->lockedBox.Front = pBox->Front; diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 4f321a931a2..2991f6c31e3 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -1428,15 +1428,11 @@ typedef struct IWineD3DVolumeImpl /* WineD3DVolume Information */ WINED3DVOLUMET_DESC currentDesc; IWineD3DBase *container; - UINT bytesPerPixel; - BOOL lockable; BOOL locked; WINED3DBOX lockedBox; WINED3DBOX dirtyBox; BOOL dirty; - - } IWineD3DVolumeImpl; extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl; @@ -1522,8 +1518,6 @@ struct IWineD3DSurfaceImpl IWineD3DPaletteImpl *palette; /* D3D7 style palette handling */ PALETTEENTRY *palette9; /* D3D8/9 style palette handling */ - UINT bytesPerPixel; - /* TODO: move this off into a management class(maybe!) */ DWORD Flags;