diff --git a/src/rlua.h b/src/rlua.h index 10a75e3a1..e9ed2c3c9 100644 --- a/src/rlua.h +++ b/src/rlua.h @@ -3232,14 +3232,6 @@ int lua_GetExtension(lua_State* L) return 1; } -int lua_GetNextPOT(lua_State* L) -{ - int arg1 = LuaGetArgument_int(L, 1); - int result = GetNextPOT(arg1); - lua_pushinteger(L, result); - return 1; -} - //---------------------------------------------------------------------------------- // raylib [raymath] module functions - Vector3 math //---------------------------------------------------------------------------------- @@ -3955,7 +3947,6 @@ static luaL_Reg raylib_functions[] = { #endif REG(TraceLog) REG(GetExtension) - REG(GetNextPOT) REG(VectorAdd) REG(VectorSubtract) REG(VectorCrossProduct) diff --git a/src/text.c b/src/text.c index 74d5940b5..4510b3af4 100644 --- a/src/text.c +++ b/src/text.c @@ -36,7 +36,7 @@ #include // Required for: va_list, va_start(), vfprintf(), va_end() #include // Required for: FILE, fopen(), fclose(), fscanf(), feof(), rewind(), fgets() -#include "utils.h" // Required for: GetExtension(), GetNextPOT() +#include "utils.h" // Required for: GetExtension() // Following libs are used on LoadTTF() #define STBTT_STATIC // Define stb_truetype functions static to this module @@ -930,7 +930,10 @@ static SpriteFont LoadTTF(const char *fileName, int fontSize, int numChars, int // NOTE: Font texture size is predicted (being as much conservative as possible) // Predictive method consist of supposing same number of chars by line-column (sqrtf) // and a maximum character width of 3/4 of fontSize... it worked ok with all my tests... - int textureSize = GetNextPOT(ceil((float)fontSize*3/4)*ceil(sqrtf((float)numChars))); + + // Calculate next power-of-two value + float guessSize = ceilf((float)fontSize*3/4)*ceilf(sqrtf((float)numChars)); + int textureSize = (int)powf(2, ceilf(logf((float)guessSize)/logf(2))); // Calculate next POT TraceLog(INFO, "TTF spritefont loading: Predicted texture size: %ix%i", textureSize, textureSize); diff --git a/src/textures.c b/src/textures.c index 6538c316c..3fa250c2d 100644 --- a/src/textures.c +++ b/src/textures.c @@ -758,9 +758,10 @@ void ImageToPOT(Image *image, Color fillColor) { 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); + // Calculate next power-of-two values + // NOTE: Just add the required amount of pixels at the right and bottom sides of image... + int potWidth = (int)powf(2, ceilf(logf((float)image->width)/logf(2))); + int potHeight = (int)powf(2, ceilf(logf((float)image->height)/logf(2))); // Check if POT texture generation is required (if texture is not already POT) if ((potWidth != image->width) || (potHeight != image->height)) @@ -1342,8 +1343,9 @@ void ImageColorBrightness(Image *image, int brightness) void GenTextureMipmaps(Texture2D *texture) { #if PLATFORM_WEB - int potWidth = GetNextPOT(texture->width); - int potHeight = GetNextPOT(texture->height); + // Calculate next power-of-two values + int potWidth = (int)powf(2, ceilf(logf((float)texture->width)/logf(2))); + int potHeight = (int)powf(2, ceilf(logf((float)texture->height)/logf(2))); // Check if texture is POT if ((potWidth != texture->width) || (potHeight != texture->height)) diff --git a/src/utils.c b/src/utils.c index 711ffab3f..e5e05955e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -52,6 +52,7 @@ #define RRES_IMPLEMENTATION #include "rres.h" +//#define NO_TRACELOG // Avoid TraceLog() output (any type) #define DO_NOT_TRACE_DEBUG_MSGS // Avoid DEBUG messages tracing //---------------------------------------------------------------------------------- @@ -74,59 +75,11 @@ static int android_close(void *cookie); //---------------------------------------------------------------------------------- // Module Functions Definition - Utilities //---------------------------------------------------------------------------------- - -#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) -// Creates a BMP image file from an array of pixel data -void SaveBMP(const char *fileName, unsigned char *imgData, int width, int height, int compSize) -{ - stbi_write_bmp(fileName, width, height, compSize, imgData); -} - -// Creates a PNG image file from an array of pixel data -void SavePNG(const char *fileName, unsigned char *imgData, int width, int height, int compSize) -{ - stbi_write_png(fileName, width, height, compSize, imgData, width*compSize); -} -#endif - -#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB) -// Outputs a trace log message (INFO, ERROR, WARNING) -// NOTE: If a file has been init, output log is written there +// Outputs a trace log message void TraceLog(int msgType, const char *text, ...) { - va_list args; - int traceDebugMsgs = 1; - -#ifdef DO_NOT_TRACE_DEBUG_MSGS - traceDebugMsgs = 0; -#endif - - switch(msgType) - { - case INFO: fprintf(stdout, "INFO: "); break; - case ERROR: fprintf(stdout, "ERROR: "); break; - case WARNING: fprintf(stdout, "WARNING: "); break; - case DEBUG: if (traceDebugMsgs) fprintf(stdout, "DEBUG: "); break; - default: break; - } - - if ((msgType != DEBUG) || ((msgType == DEBUG) && (traceDebugMsgs))) - { - va_start(args, text); - vfprintf(stdout, text, args); - va_end(args); - - fprintf(stdout, "\n"); - } - - if (msgType == ERROR) exit(1); // If ERROR message, exit program -} -#endif - -#if defined(PLATFORM_ANDROID) -void TraceLog(int msgType, const char *text, ...) -{ - static char buffer[100]; +#if !defined(NO_TRACELOG) + static char buffer[128]; int traceDebugMsgs = 1; #ifdef DO_NOT_TRACE_DEBUG_MSGS @@ -146,8 +99,9 @@ void TraceLog(int msgType, const char *text, ...) strcat(buffer, "\n"); va_list args; - va_start(args, buffer); + va_start(args, text); +#if defined(PLATFORM_ANDROID) switch(msgType) { case INFO: __android_log_vprint(ANDROID_LOG_INFO, "raylib", buffer, args); break; @@ -156,12 +110,32 @@ void TraceLog(int msgType, const char *text, ...) case DEBUG: if (traceDebugMsgs) __android_log_vprint(ANDROID_LOG_DEBUG, "raylib", buffer, args); break; default: break; } +#else + if ((msgType != DEBUG) || ((msgType == DEBUG) && (traceDebugMsgs))) vprintf(buffer, args); +#endif va_end(args); - if (msgType == ERROR) exit(1); + if (msgType == ERROR) exit(1); // If ERROR message, exit program + +#endif // NO_TRACELOG +} + +#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) +// Creates a BMP image file from an array of pixel data +void SaveBMP(const char *fileName, unsigned char *imgData, int width, int height, int compSize) +{ + stbi_write_bmp(fileName, width, height, compSize, imgData); +} + +// Creates a PNG image file from an array of pixel data +void SavePNG(const char *fileName, unsigned char *imgData, int width, int height, int compSize) +{ + stbi_write_png(fileName, width, height, compSize, imgData, width*compSize); } +#endif +#if defined(PLATFORM_ANDROID) // Initialize asset manager from android app void InitAssetManager(AAssetManager *manager) { @@ -199,23 +173,6 @@ const char *GetExtension(const char *fileName) return (dot + 1); } -// Calculate next power-of-two value for a given num -int GetNextPOT(int num) -{ - if (num != 0) - { - num--; - num |= (num >> 1); // Or first 2 bits - num |= (num >> 2); // Or next 2 bits - num |= (num >> 4); // Or next 4 bits - num |= (num >> 8); // Or next 8 bits - num |= (num >> 16); // Or next 16 bits - num++; - } - - return num; -} - //---------------------------------------------------------------------------------- // Module specific Functions Definition //---------------------------------------------------------------------------------- diff --git a/src/utils.h b/src/utils.h index e0db51fe6..3ffd025c1 100644 --- a/src/utils.h +++ b/src/utils.h @@ -43,19 +43,8 @@ //---------------------------------------------------------------------------------- // Types and Structures Definition //---------------------------------------------------------------------------------- -typedef enum { IMAGE = 0, SOUND, MODEL, TEXT, RAW } DataType; - typedef enum { INFO = 0, ERROR, WARNING, DEBUG, OTHER } TraceLogType; -// One resource info header, every resource includes this header (8 byte) -typedef struct { - unsigned short id; // Resource unique identifier (2 byte) - unsigned char type; // Resource type (1 byte) - unsigned char comp; // Data Compression and Coding (1 byte) - unsigned int size; // Data size in .rres file (compressed or not, only DATA) (4 byte) - unsigned int srcSize; // Source data size (uncompressed, only DATA) -} ResInfoHeader; - #ifdef __cplusplus extern "C" { // Prevents name mangling of functions #endif @@ -68,15 +57,14 @@ extern "C" { // Prevents name mangling of functions //---------------------------------------------------------------------------------- // Module Functions Declaration //---------------------------------------------------------------------------------- +void TraceLog(int msgType, const char *text, ...); // Outputs a trace log message +const char *GetExtension(const char *fileName); // Returns extension of a filename + #if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) void SaveBMP(const char *fileName, unsigned char *imgData, int width, int height, int compSize); void SavePNG(const char *fileName, unsigned char *imgData, int width, int height, int compSize); #endif -void TraceLog(int msgType, const char *text, ...); // Outputs a trace log message -const char *GetExtension(const char *fileName); // Returns extension of a filename -int GetNextPOT(int num); // Calculate next power-of-two value for a given num - #if defined(PLATFORM_ANDROID) void InitAssetManager(AAssetManager *manager); // Initialize asset manager from android app FILE *android_fopen(const char *fileName, const char *mode); // Replacement for fopen()