Browse Source

[rtextures] ImageDraw(): Implement drawing to mipmaps

pull/4429/head
Not-Nik 2 months ago
parent
commit
db3e68605f
No known key found for this signature in database GPG Key ID: E95F679E3CDD9784
1 changed files with 28 additions and 1 deletions
  1. +28
    -1
      src/rtextures.c

+ 28
- 1
src/rtextures.c View File

@ -3916,7 +3916,6 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color
if ((dst->data == NULL) || (dst->width == 0) || (dst->height == 0) ||
(src.data == NULL) || (src.width == 0) || (src.height == 0)) return;
if (dst->mipmaps > 1) TRACELOG(LOG_WARNING, "Image drawing only applied to base mipmap level");
if (dst->format >= PIXELFORMAT_COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "Image drawing not supported for compressed formats");
else
{
@ -4029,6 +4028,34 @@ void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec, Color
}
if (useSrcMod) UnloadImage(srcMod); // Unload source modified image
if (dst->mipmaps > 1 && src.mipmaps > 1) {
Image mipmapDst = *dst;
mipmapDst.data = (char *) mipmapDst.data + GetPixelDataSize(mipmapDst.width, mipmapDst.height, mipmapDst.format);
mipmapDst.width /= 2;
mipmapDst.height /= 2;
mipmapDst.mipmaps--;
Image mipmapSrc = src;
mipmapSrc.data = (char *) mipmapSrc.data + GetPixelDataSize(mipmapSrc.width, mipmapSrc.height, mipmapSrc.format);
mipmapSrc.width /= 2;
mipmapSrc.height /= 2;
mipmapSrc.mipmaps--;
Rectangle mipmapSrcRec = srcRec;
mipmapSrcRec.width /= 2;
mipmapSrcRec.height /= 2;
mipmapSrcRec.x /= 2;
mipmapSrcRec.y /= 2;
Rectangle mipmapDstRec = dstRec;
mipmapDstRec.width /= 2;
mipmapDstRec.height /= 2;
mipmapDstRec.x /= 2;
mipmapDstRec.y /= 2;
ImageDraw(&mipmapDst, mipmapSrc, mipmapSrcRec, mipmapDstRec, tint);
}
}
}

Loading…
Cancel
Save