|
|
@ -1719,15 +1719,15 @@ void rlglUpdateTexture(unsigned int id, int width, int height, int format, void |
|
|
|
} |
|
|
|
|
|
|
|
// Generate mipmap data for selected texture |
|
|
|
void rlglGenerateMipmaps(Texture2D texture) |
|
|
|
void rlglGenerateMipmaps(Texture2D o">*texture) |
|
|
|
{ |
|
|
|
glBindTexture(GL_TEXTURE_2D, texturep">.id); |
|
|
|
glBindTexture(GL_TEXTURE_2D, textureo">->id); |
|
|
|
|
|
|
|
// Check if texture is power-of-two (POT) |
|
|
|
bool texIsPOT = false; |
|
|
|
|
|
|
|
if (((texturep">.width > 0) && ((texturep">.width & (texturep">.width - 1)) == 0)) && |
|
|
|
((texturep">.height > 0) && ((texturep">.height & (texturep">.height - 1)) == 0))) texIsPOT = true; |
|
|
|
if (((textureo">->width > 0) && ((textureo">->width & (textureo">->width - 1)) == 0)) && |
|
|
|
((textureo">->height > 0) && ((textureo">->height & (textureo">->height - 1)) == 0))) texIsPOT = true; |
|
|
|
|
|
|
|
if ((texIsPOT) || (npotSupported)) |
|
|
|
{ |
|
|
@ -1737,13 +1737,13 @@ void rlglGenerateMipmaps(Texture2D texture) |
|
|
|
|
|
|
|
// NOTE: data size is reallocated to fit mipmaps data |
|
|
|
// NOTE: CPU mipmap generation only supports RGBA 32bit data |
|
|
|
int mipmapCount = GenerateMipmaps(data, texturep">.width, texturep">.height); |
|
|
|
int mipmapCount = GenerateMipmaps(data, textureo">->width, textureo">->height); |
|
|
|
|
|
|
|
int size = texturep">.width*texturep">.height*4; // RGBA 32bit only |
|
|
|
int size = textureo">->width*textureo">->height*4; // RGBA 32bit only |
|
|
|
int offset = size; |
|
|
|
|
|
|
|
int mipWidth = texturep">.width/2; |
|
|
|
int mipHeight = texturep">.height/2; |
|
|
|
int mipWidth = textureo">->width/2; |
|
|
|
int mipHeight = textureo">->height/2; |
|
|
|
|
|
|
|
// Load the mipmaps |
|
|
|
for (int level = 1; level < mipmapCount; level++) |
|
|
@ -1757,23 +1757,29 @@ void rlglGenerateMipmaps(Texture2D texture) |
|
|
|
mipHeight /= 2; |
|
|
|
} |
|
|
|
|
|
|
|
TraceLog(WARNING, "[TEX ID %i] Mipmaps generated manually on CPU side", texturep">.id); |
|
|
|
TraceLog(WARNING, "[TEX ID %i] Mipmaps generated manually on CPU side", textureo">->id); |
|
|
|
|
|
|
|
// NOTE: Once mipmaps have been generated and data has been uploaded to GPU VRAM, we can discard RAM data |
|
|
|
free(data); |
|
|
|
|
|
|
|
texture->mipmaps = mipmapCount + 1; |
|
|
|
#endif |
|
|
|
|
|
|
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) |
|
|
|
//glHint(GL_GENERATE_MIPMAP_HINT, GL_DONT_CARE); // Hint for mipmaps generation algorythm: GL_FASTEST, GL_NICEST, GL_DONT_CARE |
|
|
|
glGenerateMipmap(GL_TEXTURE_2D); // Generate mipmaps automatically |
|
|
|
TraceLog(INFO, "[TEX ID %i] Mipmaps generated automatically", texturep">.id); |
|
|
|
TraceLog(INFO, "[TEX ID %i] Mipmaps generated automatically", textureo">->id); |
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // Activate Trilinear filtering for mipmaps (must be available) |
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // Activate Trilinear filtering for mipmaps |
|
|
|
|
|
|
|
#define MIN(a,b) (((a)<(b))?(a):(b)) |
|
|
|
#define MAX(a,b) (((a)>(b))?(a):(b)) |
|
|
|
|
|
|
|
texture->mipmaps = 1 + floor(log2(MAX(texture->width, texture->height))); |
|
|
|
#endif |
|
|
|
} |
|
|
|
else TraceLog(WARNING, "[TEX ID %i] Mipmaps can not be generated", texture.id); |
|
|
|
else TraceLog(WARNING, "[TEX ID %i] Mipmaps can not be generated", textureo">->id); |
|
|
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0); |
|
|
|
} |
|
|
|