wined3d: Introduce a separate function to calculate the pitch for a given format and width.
This commit is contained in:
parent
a1c63c2781
commit
81fb749ecf
|
@ -2435,7 +2435,7 @@ struct wined3d_palette * CDECL wined3d_surface_get_palette(const struct wined3d_
|
|||
|
||||
DWORD CDECL wined3d_surface_get_pitch(const struct wined3d_surface *surface)
|
||||
{
|
||||
const struct wined3d_format *format = surface->resource.format;
|
||||
unsigned int alignment;
|
||||
DWORD pitch;
|
||||
|
||||
TRACE("surface %p.\n", surface);
|
||||
|
@ -2443,19 +2443,9 @@ DWORD CDECL wined3d_surface_get_pitch(const struct wined3d_surface *surface)
|
|||
if (surface->pitch)
|
||||
return surface->pitch;
|
||||
|
||||
if (format->flags & WINED3DFMT_FLAG_BLOCKS)
|
||||
{
|
||||
/* Since compressed formats are block based, pitch means the amount of
|
||||
* bytes to the next row of block rather than the next row of pixels. */
|
||||
UINT row_block_count = (surface->resource.width + format->block_width - 1) / format->block_width;
|
||||
pitch = row_block_count * format->block_byte_count;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned char alignment = surface->resource.device->surface_alignment;
|
||||
pitch = surface->resource.format->byte_count * surface->resource.width; /* Bytes / row */
|
||||
pitch = (pitch + alignment - 1) & ~(alignment - 1);
|
||||
}
|
||||
alignment = surface->resource.device->surface_alignment;
|
||||
pitch = wined3d_format_calculate_pitch(surface->resource.format, surface->resource.width);
|
||||
pitch = (pitch + alignment - 1) & ~(alignment - 1);
|
||||
|
||||
TRACE("Returning %u.\n", pitch);
|
||||
|
||||
|
|
|
@ -2019,9 +2019,20 @@ const struct wined3d_format *wined3d_get_format(const struct wined3d_gl_info *gl
|
|||
return &gl_info->formats[idx];
|
||||
}
|
||||
|
||||
UINT wined3d_format_calculate_pitch(const struct wined3d_format *format, UINT width)
|
||||
{
|
||||
/* For block based formats, pitch means the amount of bytes to the next
|
||||
* row of blocks rather than the next row of pixels. */
|
||||
if (format->flags & WINED3DFMT_FLAG_BLOCKS)
|
||||
return format->block_byte_count * ((width + format->block_width - 1) / format->block_width);
|
||||
|
||||
return format->byte_count * width;
|
||||
}
|
||||
|
||||
UINT wined3d_format_calculate_size(const struct wined3d_format *format, UINT alignment,
|
||||
UINT width, UINT height, UINT depth)
|
||||
{
|
||||
UINT pitch = wined3d_format_calculate_pitch(format, width);
|
||||
UINT size;
|
||||
|
||||
if (format->id == WINED3DFMT_UNKNOWN)
|
||||
|
@ -2030,13 +2041,12 @@ UINT wined3d_format_calculate_size(const struct wined3d_format *format, UINT ali
|
|||
}
|
||||
else if (format->flags & WINED3DFMT_FLAG_BLOCKS)
|
||||
{
|
||||
UINT row_block_count = (width + format->block_width - 1) / format->block_width;
|
||||
UINT row_count = (height + format->block_height - 1) / format->block_height;
|
||||
size = row_count * (((row_block_count * format->block_byte_count) + alignment - 1) & ~(alignment - 1));
|
||||
size = row_count * ((pitch + alignment - 1) & ~(alignment - 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
size = height * (((width * format->byte_count) + alignment - 1) & ~(alignment - 1));
|
||||
size = height * ((pitch + alignment - 1) & ~(alignment - 1));
|
||||
}
|
||||
|
||||
if (format->flags & WINED3DFMT_FLAG_HEIGHT_SCALE)
|
||||
|
|
|
@ -3040,6 +3040,7 @@ struct wined3d_format
|
|||
|
||||
const struct wined3d_format *wined3d_get_format(const struct wined3d_gl_info *gl_info,
|
||||
enum wined3d_format_id format_id) DECLSPEC_HIDDEN;
|
||||
UINT wined3d_format_calculate_pitch(const struct wined3d_format *format, UINT width) DECLSPEC_HIDDEN;
|
||||
UINT wined3d_format_calculate_size(const struct wined3d_format *format,
|
||||
UINT alignment, UINT width, UINT height, UINT depth) DECLSPEC_HIDDEN;
|
||||
DWORD wined3d_format_convert_from_float(const struct wined3d_surface *surface,
|
||||
|
|
Loading…
Reference in New Issue