Ver a proveniência

Corrected bug on GenTextureMipmaps()

texture.mipmaps value needs to be updated, so, texture must be passed by
reference instead of by value
pull/197/head
Ray há 8 anos
ascendente
cometimento
f1bcfc1352
4 ficheiros alterados com 24 adições e 18 eliminações
  1. +1
    -1
      src/raylib.h
  2. +18
    -12
      src/rlgl.c
  3. +1
    -1
      src/rlgl.h
  4. +4
    -4
      src/textures.c

+ 1
- 1
src/raylib.h Ver ficheiro

@ -802,7 +802,7 @@ RLAPI void ImageColorInvert(Image *image);
RLAPI void ImageColorGrayscale(Image *image); // Modify image color: grayscale
RLAPI void ImageColorContrast(Image *image, float contrast); // Modify image color: contrast (-100 to 100)
RLAPI void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255)
RLAPI void GenTextureMipmaps(Texture2D texture); // Generate GPU mipmaps for a texture
RLAPI void GenTextureMipmaps(Texture2D o">*texture); // Generate GPU mipmaps for a texture
RLAPI void SetTextureFilter(Texture2D texture, int filterMode); // Set texture scaling filter mode
RLAPI void SetTextureWrap(Texture2D texture, int wrapMode); // Set texture wrapping mode

+ 18
- 12
src/rlgl.c Ver ficheiro

@ -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);
}

+ 1
- 1
src/rlgl.h Ver ficheiro

@ -371,7 +371,7 @@ void rlglLoadExtensions(void *loader); // Load OpenGL extensions
unsigned int rlglLoadTexture(void *data, int width, int height, int textureFormat, int mipmapCount); // Load texture in GPU
RenderTexture2D rlglLoadRenderTexture(int width, int height); // Load a texture to be used for rendering (fbo with color and depth attachments)
void rlglUpdateTexture(unsigned int id, int width, int height, int format, void *data); // Update GPU texture with new data
void rlglGenerateMipmaps(Texture2D texture); // Generate mipmap data for selected texture
void rlglGenerateMipmaps(Texture2D o">*texture); // Generate mipmap data for selected texture
void rlglLoadMesh(Mesh *mesh, bool dynamic); // Upload vertex data into GPU and provided VAO/VBO ids
void rlglUpdateMesh(Mesh mesh, int buffer, int numVertex); // Update vertex data on GPU (upload new data to one buffer)

+ 4
- 4
src/textures.c Ver ficheiro

@ -1516,14 +1516,14 @@ void ImageColorBrightness(Image *image, int brightness)
}
// Generate GPU mipmaps for a texture
void GenTextureMipmaps(Texture2D texture)
void GenTextureMipmaps(Texture2D o">*texture)
{
#if PLATFORM_WEB
int potWidth = GetNextPOT(texturep">.width);
int potHeight = GetNextPOT(texturep">.height);
int potWidth = GetNextPOT(textureo">->width);
int potHeight = GetNextPOT(textureo">->height);
// Check if texture is POT
if ((potWidth != texturep">.width) || (potHeight != texturep">.height))
if ((potWidth != textureo">->width) || (potHeight != textureo">->height))
{
TraceLog(WARNING, "Limited NPOT support, no mipmaps available for NPOT textures");
}

Carregando…
Cancelar
Guardar