summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/rlgl.h33
-rw-r--r--src/textures.c241
2 files changed, 151 insertions, 123 deletions
diff --git a/src/rlgl.h b/src/rlgl.h
index 5d37e9a1..6bdb0324 100644
--- a/src/rlgl.h
+++ b/src/rlgl.h
@@ -579,6 +579,7 @@ RLAPI unsigned int rlLoadTextureDepth(int width, int height, bool useRenderBuffe
RLAPI unsigned int rlLoadTextureCubemap(void *data, int size, int format); // Load texture cubemap
RLAPI void rlUpdateTexture(unsigned int id, int offsetX, int offsetY, int width, int height, int format, const void *data); // Update GPU texture with new data
RLAPI void rlGetGlTextureFormats(int format, unsigned int *glInternalFormat, unsigned int *glFormat, unsigned int *glType); // Get OpenGL internal formats
+RLAPI const char *rlGetPixelFormatName(unsigned int format); // Get name string for pixel format
RLAPI void rlUnloadTexture(unsigned int id); // Unload texture from GPU memory
RLAPI void rlGenerateMipmaps(Texture2D *texture); // Generate mipmap data for selected texture
RLAPI void *rlReadTexturePixels(Texture2D texture); // Read texture pixel data
@@ -2516,7 +2517,7 @@ unsigned int rlLoadTexture(void *data, int width, int height, int format, int mi
// Unbind current texture
glBindTexture(GL_TEXTURE_2D, 0);
- if (id > 0) TRACELOG(LOG_INFO, "TEXTURE: [ID %i] Texture loaded successfully (%ix%i - %i mipmaps)", id, width, height, mipmapCount);
+ if (id > 0) TRACELOG(LOG_INFO, "TEXTURE: [ID %i] Texture loaded successfully (%ix%i | %s | %i mipmaps)", id, width, height, rlGetPixelFormatName(format), mipmapCount);
else TRACELOG(LOG_WARNING, "TEXTURE: Failed to load texture");
return id;
@@ -3733,6 +3734,36 @@ void rlLoadDrawCube(void)
#endif
}
+// Get name string for pixel format
+const char *rlGetPixelFormatName(unsigned int format)
+{
+ switch (format)
+ {
+ case PIXELFORMAT_UNCOMPRESSED_GRAYSCALE: return "GRAYSCALE"; break; // 8 bit per pixel (no alpha)
+ case PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA: return "GRAY_ALPHA"; break; // 8*2 bpp (2 channels)
+ case PIXELFORMAT_UNCOMPRESSED_R5G6B5: return "R5G6B5"; break; // 16 bpp
+ case PIXELFORMAT_UNCOMPRESSED_R8G8B8: return "R8G8B8"; break; // 24 bpp
+ case PIXELFORMAT_UNCOMPRESSED_R5G5B5A1: return "R5G5B5A1"; break; // 16 bpp (1 bit alpha)
+ case PIXELFORMAT_UNCOMPRESSED_R4G4B4A4: return "R4G4B4A4"; break; // 16 bpp (4 bit alpha)
+ case PIXELFORMAT_UNCOMPRESSED_R8G8B8A8: return "R8G8B8A8"; break; // 32 bpp
+ case PIXELFORMAT_UNCOMPRESSED_R32: return "R32"; break; // 32 bpp (1 channel - float)
+ case PIXELFORMAT_UNCOMPRESSED_R32G32B32: return "R32G32B32"; break; // 32*3 bpp (3 channels - float)
+ case PIXELFORMAT_UNCOMPRESSED_R32G32B32A32: return "R32G32B32A32"; break; // 32*4 bpp (4 channels - float)
+ case PIXELFORMAT_COMPRESSED_DXT1_RGB: return "DXT1_RGB"; break; // 4 bpp (no alpha)
+ case PIXELFORMAT_COMPRESSED_DXT1_RGBA: return "DXT1_RGBA"; break; // 4 bpp (1 bit alpha)
+ case PIXELFORMAT_COMPRESSED_DXT3_RGBA: return "DXT3_RGBA"; break; // 8 bpp
+ case PIXELFORMAT_COMPRESSED_DXT5_RGBA: return "DXT5_RGBA"; break; // 8 bpp
+ case PIXELFORMAT_COMPRESSED_ETC1_RGB: return "ETC1_RGB"; break; // 4 bpp
+ case PIXELFORMAT_COMPRESSED_ETC2_RGB: return "ETC2_RGB"; break; // 4 bpp
+ case PIXELFORMAT_COMPRESSED_ETC2_EAC_RGBA: return "ETC2_RGBA"; break; // 8 bpp
+ case PIXELFORMAT_COMPRESSED_PVRT_RGB: return "PVRT_RGB"; break; // 4 bpp
+ case PIXELFORMAT_COMPRESSED_PVRT_RGBA: return "PVRT_RGBA"; break; // 4 bpp
+ case PIXELFORMAT_COMPRESSED_ASTC_4x4_RGBA: return "ASTC_4x4_RGBA"; break; // 8 bpp
+ case PIXELFORMAT_COMPRESSED_ASTC_8x8_RGBA: return "ASTC_8x8_RGBA"; break; // 2 bpp
+ default: return "\0"; break;
+ }
+}
+
//----------------------------------------------------------------------------------
// Module specific Functions Definition
//----------------------------------------------------------------------------------
diff --git a/src/textures.c b/src/textures.c
index a9c40d50..7d1057fb 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -186,7 +186,8 @@ static Image LoadPVR(const unsigned char *fileData, unsigned int fileSize); //
#if defined(SUPPORT_FILEFORMAT_ASTC)
static Image LoadASTC(const unsigned char *fileData, unsigned int fileSize); // Load ASTC file data
#endif
-static Vector4 *LoadImageDataNormalized(Image image); // Load pixel data from image as Vector4 array (float normalized)
+
+static Vector4 *LoadImageDataNormalized(Image image); // Load pixel data from image as Vector4 array (float normalized)
//----------------------------------------------------------------------------------
// Module Functions Definition
@@ -212,16 +213,10 @@ Image LoadImage(const char *fileName)
unsigned int fileSize = 0;
unsigned char *fileData = LoadFileData(fileName, &fileSize);
- if (fileData != NULL)
- {
- // Loading image from memory data
- image = LoadImageFromMemory(GetFileExtension(fileName), fileData, fileSize);
-
- if (image.data != NULL) TRACELOG(LOG_INFO, "IMAGE: [%s] Data loaded successfully (%ix%i)", fileName, image.width, image.height);
- else TRACELOG(LOG_WARNING, "IMAGE: [%s] Failed to load data", fileName);
+ // Loading image from memory data
+ if (fileData != NULL) image = LoadImageFromMemory(GetFileExtension(fileName), fileData, fileSize);
- RL_FREE(fileData);
- }
+ RL_FREE(fileData);
return image;
}
@@ -383,7 +378,9 @@ Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, i
#if defined(SUPPORT_FILEFORMAT_ASTC)
else if (TextIsEqual(fileExtLower, ".astc")) image = LoadASTC(fileData, dataSize);
#endif
- else TRACELOG(LOG_WARNING, "IMAGE: File format not supported");
+ else TRACELOG(LOG_WARNING, "IMAGE: Data format not supported");
+
+ TRACELOG(LOG_INFO, "IMAGE: Data loaded successfully (%ix%i | %s | %i mipmaps)", image.width, image.height, rlGetPixelFormatName(image.format), image.mipmaps);
return image;
}
@@ -2203,117 +2200,6 @@ void UnloadImagePalette(Color *colors)
RL_FREE(colors);
}
-// Get pixel data from image as Vector4 array (float normalized)
-static Vector4 *LoadImageDataNormalized(Image image)
-{
- Vector4 *pixels = (Vector4 *)RL_MALLOC(image.width*image.height*sizeof(Vector4));
-
- if (image.format >= PIXELFORMAT_COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "IMAGE: Pixel data retrieval not supported for compressed image formats");
- else
- {
- for (int i = 0, k = 0; i < image.width*image.height; i++)
- {
- switch (image.format)
- {
- case PIXELFORMAT_UNCOMPRESSED_GRAYSCALE:
- {
- pixels[i].x = (float)((unsigned char *)image.data)[i]/255.0f;
- pixels[i].y = (float)((unsigned char *)image.data)[i]/255.0f;
- pixels[i].z = (float)((unsigned char *)image.data)[i]/255.0f;
- pixels[i].w = 1.0f;
-
- } break;
- case PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA:
- {
- pixels[i].x = (float)((unsigned char *)image.data)[k]/255.0f;
- pixels[i].y = (float)((unsigned char *)image.data)[k]/255.0f;
- pixels[i].z = (float)((unsigned char *)image.data)[k]/255.0f;
- pixels[i].w = (float)((unsigned char *)image.data)[k + 1]/255.0f;
-
- k += 2;
- } break;
- case PIXELFORMAT_UNCOMPRESSED_R5G5B5A1:
- {
- unsigned short pixel = ((unsigned short *)image.data)[i];
-
- pixels[i].x = (float)((pixel & 0b1111100000000000) >> 11)*(1.0f/31);
- pixels[i].y = (float)((pixel & 0b0000011111000000) >> 6)*(1.0f/31);
- pixels[i].z = (float)((pixel & 0b0000000000111110) >> 1)*(1.0f/31);
- pixels[i].w = ((pixel & 0b0000000000000001) == 0)? 0.0f : 1.0f;
-
- } break;
- case PIXELFORMAT_UNCOMPRESSED_R5G6B5:
- {
- unsigned short pixel = ((unsigned short *)image.data)[i];
-
- pixels[i].x = (float)((pixel & 0b1111100000000000) >> 11)*(1.0f/31);
- pixels[i].y = (float)((pixel & 0b0000011111100000) >> 5)*(1.0f/63);
- pixels[i].z = (float)(pixel & 0b0000000000011111)*(1.0f/31);
- pixels[i].w = 1.0f;
-
- } break;
- case PIXELFORMAT_UNCOMPRESSED_R4G4B4A4:
- {
- unsigned short pixel = ((unsigned short *)image.data)[i];
-
- pixels[i].x = (float)((pixel & 0b1111000000000000) >> 12)*(1.0f/15);
- pixels[i].y = (float)((pixel & 0b0000111100000000) >> 8)*(1.0f/15);
- pixels[i].z = (float)((pixel & 0b0000000011110000) >> 4)*(1.0f/15);
- pixels[i].w = (float)(pixel & 0b0000000000001111)*(1.0f/15);
-
- } break;
- case PIXELFORMAT_UNCOMPRESSED_R8G8B8A8:
- {
- pixels[i].x = (float)((unsigned char *)image.data)[k]/255.0f;
- pixels[i].y = (float)((unsigned char *)image.data)[k + 1]/255.0f;
- pixels[i].z = (float)((unsigned char *)image.data)[k + 2]/255.0f;
- pixels[i].w = (float)((unsigned char *)image.data)[k + 3]/255.0f;
-
- k += 4;
- } break;
- case PIXELFORMAT_UNCOMPRESSED_R8G8B8:
- {
- pixels[i].x = (float)((unsigned char *)image.data)[k]/255.0f;
- pixels[i].y = (float)((unsigned char *)image.data)[k + 1]/255.0f;
- pixels[i].z = (float)((unsigned char *)image.data)[k + 2]/255.0f;
- pixels[i].w = 1.0f;
-
- k += 3;
- } break;
- case PIXELFORMAT_UNCOMPRESSED_R32:
- {
- pixels[i].x = ((float *)image.data)[k];
- pixels[i].y = 0.0f;
- pixels[i].z = 0.0f;
- pixels[i].w = 1.0f;
-
- } break;
- case PIXELFORMAT_UNCOMPRESSED_R32G32B32:
- {
- pixels[i].x = ((float *)image.data)[k];
- pixels[i].y = ((float *)image.data)[k + 1];
- pixels[i].z = ((float *)image.data)[k + 2];
- pixels[i].w = 1.0f;
-
- k += 3;
- } break;
- case PIXELFORMAT_UNCOMPRESSED_R32G32B32A32:
- {
- pixels[i].x = ((float *)image.data)[k];
- pixels[i].y = ((float *)image.data)[k + 1];
- pixels[i].z = ((float *)image.data)[k + 2];
- pixels[i].w = ((float *)image.data)[k + 3];
-
- k += 4;
- }
- default: break;
- }
- }
- }
-
- return pixels;
-}
-
// Get image alpha border rectangle
// NOTE: Threshold is defined as a percentatge: 0.0f -> 1.0f
Rectangle GetImageAlphaBorder(Image image, float threshold)
@@ -4600,3 +4486,114 @@ static Image LoadASTC(const unsigned char *fileData, unsigned int fileSize)
return image;
}
#endif
+
+// Get pixel data from image as Vector4 array (float normalized)
+static Vector4 *LoadImageDataNormalized(Image image)
+{
+ Vector4 *pixels = (Vector4 *)RL_MALLOC(image.width*image.height*sizeof(Vector4));
+
+ if (image.format >= PIXELFORMAT_COMPRESSED_DXT1_RGB) TRACELOG(LOG_WARNING, "IMAGE: Pixel data retrieval not supported for compressed image formats");
+ else
+ {
+ for (int i = 0, k = 0; i < image.width*image.height; i++)
+ {
+ switch (image.format)
+ {
+ case PIXELFORMAT_UNCOMPRESSED_GRAYSCALE:
+ {
+ pixels[i].x = (float)((unsigned char *)image.data)[i]/255.0f;
+ pixels[i].y = (float)((unsigned char *)image.data)[i]/255.0f;
+ pixels[i].z = (float)((unsigned char *)image.data)[i]/255.0f;
+ pixels[i].w = 1.0f;
+
+ } break;
+ case PIXELFORMAT_UNCOMPRESSED_GRAY_ALPHA:
+ {
+ pixels[i].x = (float)((unsigned char *)image.data)[k]/255.0f;
+ pixels[i].y = (float)((unsigned char *)image.data)[k]/255.0f;
+ pixels[i].z = (float)((unsigned char *)image.data)[k]/255.0f;
+ pixels[i].w = (float)((unsigned char *)image.data)[k + 1]/255.0f;
+
+ k += 2;
+ } break;
+ case PIXELFORMAT_UNCOMPRESSED_R5G5B5A1:
+ {
+ unsigned short pixel = ((unsigned short *)image.data)[i];
+
+ pixels[i].x = (float)((pixel & 0b1111100000000000) >> 11)*(1.0f/31);
+ pixels[i].y = (float)((pixel & 0b0000011111000000) >> 6)*(1.0f/31);
+ pixels[i].z = (float)((pixel & 0b0000000000111110) >> 1)*(1.0f/31);
+ pixels[i].w = ((pixel & 0b0000000000000001) == 0)? 0.0f : 1.0f;
+
+ } break;
+ case PIXELFORMAT_UNCOMPRESSED_R5G6B5:
+ {
+ unsigned short pixel = ((unsigned short *)image.data)[i];
+
+ pixels[i].x = (float)((pixel & 0b1111100000000000) >> 11)*(1.0f/31);
+ pixels[i].y = (float)((pixel & 0b0000011111100000) >> 5)*(1.0f/63);
+ pixels[i].z = (float)(pixel & 0b0000000000011111)*(1.0f/31);
+ pixels[i].w = 1.0f;
+
+ } break;
+ case PIXELFORMAT_UNCOMPRESSED_R4G4B4A4:
+ {
+ unsigned short pixel = ((unsigned short *)image.data)[i];
+
+ pixels[i].x = (float)((pixel & 0b1111000000000000) >> 12)*(1.0f/15);
+ pixels[i].y = (float)((pixel & 0b0000111100000000) >> 8)*(1.0f/15);
+ pixels[i].z = (float)((pixel & 0b0000000011110000) >> 4)*(1.0f/15);
+ pixels[i].w = (float)(pixel & 0b0000000000001111)*(1.0f/15);
+
+ } break;
+ case PIXELFORMAT_UNCOMPRESSED_R8G8B8A8:
+ {
+ pixels[i].x = (float)((unsigned char *)image.data)[k]/255.0f;
+ pixels[i].y = (float)((unsigned char *)image.data)[k + 1]/255.0f;
+ pixels[i].z = (float)((unsigned char *)image.data)[k + 2]/255.0f;
+ pixels[i].w = (float)((unsigned char *)image.data)[k + 3]/255.0f;
+
+ k += 4;
+ } break;
+ case PIXELFORMAT_UNCOMPRESSED_R8G8B8:
+ {
+ pixels[i].x = (float)((unsigned char *)image.data)[k]/255.0f;
+ pixels[i].y = (float)((unsigned char *)image.data)[k + 1]/255.0f;
+ pixels[i].z = (float)((unsigned char *)image.data)[k + 2]/255.0f;
+ pixels[i].w = 1.0f;
+
+ k += 3;
+ } break;
+ case PIXELFORMAT_UNCOMPRESSED_R32:
+ {
+ pixels[i].x = ((float *)image.data)[k];
+ pixels[i].y = 0.0f;
+ pixels[i].z = 0.0f;
+ pixels[i].w = 1.0f;
+
+ } break;
+ case PIXELFORMAT_UNCOMPRESSED_R32G32B32:
+ {
+ pixels[i].x = ((float *)image.data)[k];
+ pixels[i].y = ((float *)image.data)[k + 1];
+ pixels[i].z = ((float *)image.data)[k + 2];
+ pixels[i].w = 1.0f;
+
+ k += 3;
+ } break;
+ case PIXELFORMAT_UNCOMPRESSED_R32G32B32A32:
+ {
+ pixels[i].x = ((float *)image.data)[k];
+ pixels[i].y = ((float *)image.data)[k + 1];
+ pixels[i].z = ((float *)image.data)[k + 2];
+ pixels[i].w = ((float *)image.data)[k + 3];
+
+ k += 4;
+ }
+ default: break;
+ }
+ }
+ }
+
+ return pixels;
+}