Skip to content

Commit

Permalink
Reviewed PR #3321
Browse files Browse the repository at this point in the history
  • Loading branch information
raysan5 committed Sep 18, 2023
1 parent eb46151 commit b335927
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/rlgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2997,7 +2997,10 @@ unsigned int rlLoadTexture(const void *data, int width, int height, int format,

int mipWidth = width;
int mipHeight = height;
int mipOffset = 0; // Mipmap data offset
int mipOffset = 0; // Mipmap data offset, only used for tracelog

// NOTE: Added pointer math separately from function to avoid UBSAN complaining
unsigned char *dataPtr = (unsigned char *)data;

// Load the different mipmap levels
for (int i = 0; i < mipmapCount; i++)
Expand All @@ -3009,10 +3012,6 @@ unsigned int rlLoadTexture(const void *data, int width, int height, int format,

TRACELOGD("TEXTURE: Load mipmap level %i (%i x %i), size: %i, offset: %i", i, mipWidth, mipHeight, mipSize, mipOffset);

// NOTE: Added pointer math separately from function to avoid UBSAN complaining
unsigned char *dataPtr = (unsigned char*)data;
if (mipOffset > 0) dataPtr = (unsigned char*)data + mipOffset;

if (glInternalFormat != -1)
{
if (format < RL_PIXELFORMAT_COMPRESSED_DXT1_RGB) glTexImage2D(GL_TEXTURE_2D, i, glInternalFormat, mipWidth, mipHeight, 0, glFormat, glType, dataPtr);
Expand Down Expand Up @@ -3040,7 +3039,8 @@ unsigned int rlLoadTexture(const void *data, int width, int height, int format,

mipWidth /= 2;
mipHeight /= 2;
mipOffset += mipSize;
mipOffset += mipSize; // Increment offset position to next mipmap
dataPtr += mipSize; // Increment data pointer to next mipmap

// Security check for NPOT textures
if (mipWidth < 1) mipWidth = 1;
Expand Down

0 comments on commit b335927

Please sign in to comment.