Reviewed ImageConvertToPOT()
This commit is contained in:
parent
fd2b0c7c38
commit
07858c3a1f
1 changed files with 135 additions and 128 deletions
|
@ -330,7 +330,6 @@ Texture2D LoadTexture(const char *fileName)
|
|||
else
|
||||
{
|
||||
TraceLog(WARNING, "Texture could not be created");
|
||||
|
||||
texture.id = 0;
|
||||
}
|
||||
|
||||
|
@ -391,7 +390,8 @@ void UnloadImage(Image image)
|
|||
{
|
||||
free(image.data);
|
||||
|
||||
TraceLog(INFO, "Unloaded image data");
|
||||
// NOTE: It becomes anoying every time a texture is loaded
|
||||
//TraceLog(INFO, "Unloaded image data");
|
||||
}
|
||||
|
||||
// Unload texture from GPU memory
|
||||
|
@ -519,7 +519,9 @@ Image GetTextureData(Texture2D texture)
|
|||
// Convert image data to desired format
|
||||
void ImageConvertFormat(Image *image, int newFormat)
|
||||
{
|
||||
if ((image->format != newFormat) && (image->format < 8) && (newFormat < 8))
|
||||
if (image->format != newFormat)
|
||||
{
|
||||
if ((image->format < 8) && (newFormat < 8))
|
||||
{
|
||||
Color *pixels = GetImageData(*image);
|
||||
|
||||
|
@ -650,14 +652,15 @@ void ImageConvertFormat(Image *image, int newFormat)
|
|||
}
|
||||
else TraceLog(WARNING, "Image data format is compressed, can not be converted");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Convert image to POT (power-of-two)
|
||||
// NOTE: Requirement on OpenGL ES 2.0 (RPI, HTML5)
|
||||
void ImageConvertToPOT(Image *image, Color fillColor)
|
||||
{
|
||||
// TODO: Review for new image struct
|
||||
/*
|
||||
Color *pixels = GetImageData(*image); // Get pixels data
|
||||
|
||||
// Just add the required amount of pixels at the right and bottom sides of image...
|
||||
int potWidth = GetNextPOT(image->width);
|
||||
int potHeight = GetNextPOT(image->height);
|
||||
|
@ -665,29 +668,33 @@ void ImageConvertToPOT(Image *image, Color fillColor)
|
|||
// Check if POT texture generation is required (if texture is not already POT)
|
||||
if ((potWidth != image->width) || (potHeight != image->height))
|
||||
{
|
||||
Color *imgDataPixelPOT = NULL;
|
||||
Color *pixelsPOT = NULL;
|
||||
|
||||
// Generate POT array from NPOT data
|
||||
imgDataPixelPOT = (Color *)malloc(potWidth * potHeight * sizeof(Color));
|
||||
pixelsPOT = (Color *)malloc(potWidth * potHeight * sizeof(Color));
|
||||
|
||||
for (int j = 0; j < potHeight; j++)
|
||||
{
|
||||
for (int i = 0; i < potWidth; i++)
|
||||
{
|
||||
if ((j < image->height) && (i < image->width)) imgDataPixelPOT[j*potWidth + i] = image->data[j*image->width + i];
|
||||
else imgDataPixelPOT[j*potWidth + i] = fillColor;
|
||||
if ((j < image->height) && (i < image->width)) pixelsPOT[j*potWidth + i] = pixels[j*image->width + i];
|
||||
else pixelsPOT[j*potWidth + i] = fillColor;
|
||||
}
|
||||
}
|
||||
|
||||
TraceLog(WARNING, "Image converted to POT: (%ix%i) -> (%ix%i)", image->width, image->height, potWidth, potHeight);
|
||||
|
||||
free(image->pixels);
|
||||
free(pixels); // Free pixels data
|
||||
free(image->data); // Free old image data
|
||||
|
||||
image->pixels = imgDataPixelPOT;
|
||||
image->width = potWidth;
|
||||
image->height = potHeight;
|
||||
int format = image->format; // Store image data format to reconvert later
|
||||
|
||||
*image = LoadImageEx(pixelsPOT, potWidth, potHeight);
|
||||
|
||||
free(pixelsPOT); // Free POT pixels data
|
||||
|
||||
ImageConvertFormat(image, format); // Reconvert image to previous format
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// Copy an image to a new image
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue