Commit 6e5a5d27 authored by Stefan Dösinger's avatar Stefan Dösinger Committed by Alexandre Julliard

wined3d: DDraw surfaces are QWORD aligned.

parent 078523f7
...@@ -347,10 +347,10 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar ...@@ -347,10 +347,10 @@ WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *tar
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
checkGLcall("glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);"); checkGLcall("glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);");
glPixelStorei(GL_PACK_ALIGNMENT, SURFACE_ALIGNMENT); glPixelStorei(GL_PACK_ALIGNMENT, This->surface_alignment);
checkGLcall("glPixelStorei(GL_PACK_ALIGNMENT, SURFACE_ALIGNMENT);"); checkGLcall("glPixelStorei(GL_PACK_ALIGNMENT, This->surface_alignment);");
glPixelStorei(GL_UNPACK_ALIGNMENT, SURFACE_ALIGNMENT); glPixelStorei(GL_UNPACK_ALIGNMENT, This->surface_alignment);
checkGLcall("glPixelStorei(GL_UNPACK_ALIGNMENT, SURFACE_ALIGNMENT);"); checkGLcall("glPixelStorei(GL_UNPACK_ALIGNMENT, This->surface_alignment);");
if(GL_SUPPORT(APPLE_CLIENT_STORAGE)) { if(GL_SUPPORT(APPLE_CLIENT_STORAGE)) {
/* Most textures will use client storage if supported. Exceptions are non-native power of 2 textures /* Most textures will use client storage if supported. Exceptions are non-native power of 2 textures
......
...@@ -674,7 +674,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateSurface(IWineD3DDevice *iface, U ...@@ -674,7 +674,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateSurface(IWineD3DDevice *iface, U
Size = ((max(Width,4) * tableEntry->bpp) * max(Height,4)); Size = ((max(Width,4) * tableEntry->bpp) * max(Height,4));
} else { } else {
/* The pitch is a multiple of 4 bytes */ /* The pitch is a multiple of 4 bytes */
Size = ((Width * tableEntry->bpp) + SURFACE_ALIGNMENT - 1) & ~(SURFACE_ALIGNMENT - 1); Size = ((Width * tableEntry->bpp) + This->surface_alignment - 1) & ~(This->surface_alignment - 1);
Size *= Height; Size *= Height;
} }
......
...@@ -2462,6 +2462,12 @@ static HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT Adapter, ...@@ -2462,6 +2462,12 @@ static HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT Adapter,
IWineD3D_AddRef(object->wineD3D); IWineD3D_AddRef(object->wineD3D);
object->parent = parent; object->parent = parent;
if(This->dxVersion == 7) {
object->surface_alignment = 8;
} else {
object->surface_alignment = 4;
}
/* Set the state up as invalid until the device is fully created */ /* Set the state up as invalid until the device is fully created */
object->state = WINED3DERR_DRIVERINTERNALERROR; object->state = WINED3DERR_DRIVERINTERNALERROR;
......
...@@ -79,9 +79,10 @@ static void surface_download_data(IWineD3DSurfaceImpl *This) { ...@@ -79,9 +79,10 @@ static void surface_download_data(IWineD3DSurfaceImpl *This) {
} }
if (This->Flags & SFLAG_NONPOW2) { if (This->Flags & SFLAG_NONPOW2) {
unsigned char alignment = This->resource.wineD3DDevice->surface_alignment;
src_pitch = This->bytesPerPixel * This->pow2Width; src_pitch = This->bytesPerPixel * This->pow2Width;
dst_pitch = IWineD3DSurface_GetPitch((IWineD3DSurface *) This); dst_pitch = IWineD3DSurface_GetPitch((IWineD3DSurface *) This);
src_pitch = (src_pitch + SURFACE_ALIGNMENT - 1) & ~(SURFACE_ALIGNMENT - 1); src_pitch = (src_pitch + alignment - 1) & ~(alignment - 1);
mem = HeapAlloc(GetProcessHeap(), 0, src_pitch * This->pow2Height); mem = HeapAlloc(GetProcessHeap(), 0, src_pitch * This->pow2Height);
} else { } else {
mem = This->resource.allocatedMemory; mem = This->resource.allocatedMemory;
...@@ -1320,7 +1321,8 @@ HRESULT WINAPI IWineD3DSurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC) { ...@@ -1320,7 +1321,8 @@ HRESULT WINAPI IWineD3DSurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHDC) {
} }
b_info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); b_info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
b_info->bmiHeader.biWidth = This->currentDesc.Width; /* 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.biHeight = -This->currentDesc.Height -extraline; b_info->bmiHeader.biHeight = -This->currentDesc.Height -extraline;
b_info->bmiHeader.biSizeImage = ( This->currentDesc.Height + extraline) * IWineD3DSurface_GetPitch(iface); b_info->bmiHeader.biSizeImage = ( This->currentDesc.Height + extraline) * IWineD3DSurface_GetPitch(iface);
b_info->bmiHeader.biPlanes = 1; b_info->bmiHeader.biPlanes = 1;
...@@ -1978,7 +1980,7 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_LoadTexture(IWineD3DSurface *iface, BO ...@@ -1978,7 +1980,7 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_LoadTexture(IWineD3DSurface *iface, BO
/* Stick to the alignment for the converted surface too, makes it easier to load the surface */ /* Stick to the alignment for the converted surface too, makes it easier to load the surface */
outpitch = width * bpp; outpitch = width * bpp;
outpitch = (outpitch + SURFACE_ALIGNMENT - 1) & ~(SURFACE_ALIGNMENT - 1); outpitch = (outpitch + device->surface_alignment - 1) & ~(device->surface_alignment - 1);
mem = HeapAlloc(GetProcessHeap(), 0, outpitch * height); mem = HeapAlloc(GetProcessHeap(), 0, outpitch * height);
if(!mem) { if(!mem) {
...@@ -2264,7 +2266,8 @@ HRESULT WINAPI IWineD3DSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORM ...@@ -2264,7 +2266,8 @@ HRESULT WINAPI IWineD3DSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORM
format == WINED3DFMT_DXT4 || format == WINED3DFMT_DXT5) { format == WINED3DFMT_DXT4 || format == WINED3DFMT_DXT5) {
This->resource.size = ((max(This->pow2Width, 4) * formatEntry->bpp) * max(This->pow2Height, 4)); This->resource.size = ((max(This->pow2Width, 4) * formatEntry->bpp) * max(This->pow2Height, 4));
} else { } else {
This->resource.size = ((This->pow2Width * formatEntry->bpp) + SURFACE_ALIGNMENT - 1) & ~(SURFACE_ALIGNMENT - 1); unsigned char alignment = This->resource.wineD3DDevice->surface_alignment;
This->resource.size = ((This->pow2Width * formatEntry->bpp) + alignment - 1) & ~(alignment - 1);
This->resource.size *= This->pow2Height; This->resource.size *= This->pow2Height;
} }
...@@ -3483,9 +3486,9 @@ DWORD WINAPI IWineD3DSurfaceImpl_GetPitch(IWineD3DSurface *iface) { ...@@ -3483,9 +3486,9 @@ DWORD WINAPI IWineD3DSurfaceImpl_GetPitch(IWineD3DSurface *iface) {
This->resource.format == WINED3DFMT_DXT4 || This->resource.format == WINED3DFMT_DXT5) /* DXT2/3/4/5 is 16 bytes per block */ This->resource.format == WINED3DFMT_DXT4 || This->resource.format == WINED3DFMT_DXT5) /* DXT2/3/4/5 is 16 bytes per block */
ret = ((This->currentDesc.Width + 3) >> 2) << 4; ret = ((This->currentDesc.Width + 3) >> 2) << 4;
else { else {
unsigned char alignment = This->resource.wineD3DDevice->surface_alignment;
ret = This->bytesPerPixel * This->currentDesc.Width; /* Bytes / row */ ret = This->bytesPerPixel * This->currentDesc.Width; /* Bytes / row */
/* Surfaces are 32 bit aligned */ ret = (ret + alignment - 1) & ~(alignment - 1);
ret = (ret + SURFACE_ALIGNMENT - 1) & ~(SURFACE_ALIGNMENT - 1);
} }
TRACE("(%p) Returning %d\n", This, ret); TRACE("(%p) Returning %d\n", This, ret);
return ret; return ret;
......
...@@ -647,6 +647,7 @@ struct IWineD3DDeviceImpl ...@@ -647,6 +647,7 @@ struct IWineD3DDeviceImpl
BOOL view_ident; /* true iff view matrix is identity */ BOOL view_ident; /* true iff view matrix is identity */
BOOL untransformed; BOOL untransformed;
BOOL vertexBlendUsed; /* To avoid needless setting of the blend matrices */ BOOL vertexBlendUsed; /* To avoid needless setting of the blend matrices */
unsigned char surface_alignment; /* Line Alignment of surfaces */
/* State block related */ /* State block related */
BOOL isRecordingState; BOOL isRecordingState;
...@@ -1184,9 +1185,6 @@ HRESULT WINAPI IWineD3DSurfaceImpl_GetClipper(IWineD3DSurface *iface, IWineD3DCl ...@@ -1184,9 +1185,6 @@ HRESULT WINAPI IWineD3DSurfaceImpl_GetClipper(IWineD3DSurface *iface, IWineD3DCl
BOOL CalculateTexRect(IWineD3DSurfaceImpl *This, RECT *Rect, float glTexCoord[4]); BOOL CalculateTexRect(IWineD3DSurfaceImpl *This, RECT *Rect, float glTexCoord[4]);
/* Alignment of the pitch */
#define SURFACE_ALIGNMENT 4
/***************************************************************************** /*****************************************************************************
* IWineD3DVertexDeclaration implementation structure * IWineD3DVertexDeclaration implementation structure
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment