Corrected issue on mipmaps generations
This commit is contained in:
parent
552033da27
commit
14d3b0a084
1 changed files with 16 additions and 9 deletions
23
src/rlgl.c
23
src/rlgl.c
|
@ -1809,17 +1809,21 @@ void rlglGenerateMipmaps(unsigned int textureId)
|
||||||
{
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D, textureId);
|
glBindTexture(GL_TEXTURE_2D, textureId);
|
||||||
|
|
||||||
|
// Check if texture is power-of-two (POT)
|
||||||
|
bool texIsPOT = false;
|
||||||
|
|
||||||
|
// NOTE: In OpenGL ES 2.0 we have no way to retrieve texture size from id
|
||||||
|
|
||||||
|
#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
|
||||||
int width, height;
|
int width, height;
|
||||||
|
|
||||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
|
||||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
|
||||||
|
|
||||||
// Check if texture is power-of-two (POT) to enable mipmap generation
|
|
||||||
bool texIsPOT = false;
|
|
||||||
|
|
||||||
if (((width > 0) && ((width & (width - 1)) == 0)) && ((height > 0) && ((height & (height - 1)) == 0))) texIsPOT = true;
|
if (((width > 0) && ((width & (width - 1)) == 0)) && ((height > 0) && ((height & (height - 1)) == 0))) texIsPOT = true;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (texIsPOT)
|
if ((texIsPOT) || (npotSupported))
|
||||||
{
|
{
|
||||||
#if defined(GRAPHICS_API_OPENGL_11)
|
#if defined(GRAPHICS_API_OPENGL_11)
|
||||||
// Compute required mipmaps
|
// Compute required mipmaps
|
||||||
|
@ -1852,14 +1856,12 @@ void rlglGenerateMipmaps(unsigned int textureId)
|
||||||
#elif defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
#elif defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
glGenerateMipmap(GL_TEXTURE_2D); // Generate mipmaps automatically
|
glGenerateMipmap(GL_TEXTURE_2D); // Generate mipmaps automatically
|
||||||
TraceLog(INFO, "[TEX ID %i] Mipmaps generated automatically", textureId);
|
TraceLog(INFO, "[TEX ID %i] Mipmaps generated automatically", textureId);
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(GRAPHICS_API_OPENGL_33)
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
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 (must be available)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else TraceLog(WARNING, "[TEX ID %i] Texture is not power-of-two, mipmaps can not be generated", textureId);
|
else TraceLog(WARNING, "[TEX ID %i] Mipmaps can not be generated", textureId);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
|
@ -1965,8 +1967,12 @@ unsigned char *rlglReadScreenPixels(int width, int height)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read texture pixel data
|
// Read texture pixel data
|
||||||
|
// NOTE: Retrieving pixel data from GPU not supported on OpenGL ES 2.0
|
||||||
void *rlglReadTexturePixels(unsigned int textureId, unsigned int format)
|
void *rlglReadTexturePixels(unsigned int textureId, unsigned int format)
|
||||||
{
|
{
|
||||||
|
void *pixels = NULL;
|
||||||
|
|
||||||
|
#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
|
||||||
int width, height;
|
int width, height;
|
||||||
|
|
||||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
|
||||||
|
@ -1975,7 +1981,7 @@ void *rlglReadTexturePixels(unsigned int textureId, unsigned int format)
|
||||||
//GL_TEXTURE_RED_SIZE, GL_TEXTURE_GREEN_SIZE, GL_TEXTURE_BLUE_SIZE, GL_TEXTURE_ALPHA_SIZE
|
//GL_TEXTURE_RED_SIZE, GL_TEXTURE_GREEN_SIZE, GL_TEXTURE_BLUE_SIZE, GL_TEXTURE_ALPHA_SIZE
|
||||||
|
|
||||||
int glFormat = 0, glType = 0;
|
int glFormat = 0, glType = 0;
|
||||||
void *pixels = NULL;
|
|
||||||
unsigned int size = width*height;
|
unsigned int size = width*height;
|
||||||
|
|
||||||
switch (format)
|
switch (format)
|
||||||
|
@ -2001,6 +2007,7 @@ void *rlglReadTexturePixels(unsigned int textureId, unsigned int format)
|
||||||
glGetTexImage(GL_TEXTURE_2D, 0, glFormat, glType, pixels);
|
glGetTexImage(GL_TEXTURE_2D, 0, glFormat, glType, pixels);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
return pixels;
|
return pixels;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue