Removed GetNextPOT(), review TraceLog()
This commit is contained in:
parent
4a158d972d
commit
61f6b0f707
5 changed files with 42 additions and 101 deletions
|
@ -3232,14 +3232,6 @@ int lua_GetExtension(lua_State* L)
|
||||||
return 1;
|
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
|
// raylib [raymath] module functions - Vector3 math
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
@ -3955,7 +3947,6 @@ static luaL_Reg raylib_functions[] = {
|
||||||
#endif
|
#endif
|
||||||
REG(TraceLog)
|
REG(TraceLog)
|
||||||
REG(GetExtension)
|
REG(GetExtension)
|
||||||
REG(GetNextPOT)
|
|
||||||
REG(VectorAdd)
|
REG(VectorAdd)
|
||||||
REG(VectorSubtract)
|
REG(VectorSubtract)
|
||||||
REG(VectorCrossProduct)
|
REG(VectorCrossProduct)
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
|
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
|
||||||
#include <stdio.h> // Required for: FILE, fopen(), fclose(), fscanf(), feof(), rewind(), fgets()
|
#include <stdio.h> // 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()
|
// Following libs are used on LoadTTF()
|
||||||
#define STBTT_STATIC // Define stb_truetype functions static to this module
|
#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)
|
// 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)
|
// 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...
|
// 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);
|
TraceLog(INFO, "TTF spritefont loading: Predicted texture size: %ix%i", textureSize, textureSize);
|
||||||
|
|
||||||
|
|
|
@ -758,9 +758,10 @@ void ImageToPOT(Image *image, Color fillColor)
|
||||||
{
|
{
|
||||||
Color *pixels = GetImageData(*image); // Get pixels data
|
Color *pixels = GetImageData(*image); // Get pixels data
|
||||||
|
|
||||||
// Just add the required amount of pixels at the right and bottom sides of image...
|
// Calculate next power-of-two values
|
||||||
int potWidth = GetNextPOT(image->width);
|
// NOTE: Just add the required amount of pixels at the right and bottom sides of image...
|
||||||
int potHeight = GetNextPOT(image->height);
|
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)
|
// Check if POT texture generation is required (if texture is not already POT)
|
||||||
if ((potWidth != image->width) || (potHeight != image->height))
|
if ((potWidth != image->width) || (potHeight != image->height))
|
||||||
|
@ -1342,8 +1343,9 @@ void ImageColorBrightness(Image *image, int brightness)
|
||||||
void GenTextureMipmaps(Texture2D *texture)
|
void GenTextureMipmaps(Texture2D *texture)
|
||||||
{
|
{
|
||||||
#if PLATFORM_WEB
|
#if PLATFORM_WEB
|
||||||
int potWidth = GetNextPOT(texture->width);
|
// Calculate next power-of-two values
|
||||||
int potHeight = GetNextPOT(texture->height);
|
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
|
// Check if texture is POT
|
||||||
if ((potWidth != texture->width) || (potHeight != texture->height))
|
if ((potWidth != texture->width) || (potHeight != texture->height))
|
||||||
|
|
97
src/utils.c
97
src/utils.c
|
@ -52,6 +52,7 @@
|
||||||
#define RRES_IMPLEMENTATION
|
#define RRES_IMPLEMENTATION
|
||||||
#include "rres.h"
|
#include "rres.h"
|
||||||
|
|
||||||
|
//#define NO_TRACELOG // Avoid TraceLog() output (any type)
|
||||||
#define DO_NOT_TRACE_DEBUG_MSGS // Avoid DEBUG messages tracing
|
#define DO_NOT_TRACE_DEBUG_MSGS // Avoid DEBUG messages tracing
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
@ -74,59 +75,11 @@ static int android_close(void *cookie);
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module Functions Definition - Utilities
|
// Module Functions Definition - Utilities
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
// Outputs a trace log message
|
||||||
#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
|
|
||||||
void TraceLog(int msgType, const char *text, ...)
|
void TraceLog(int msgType, const char *text, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
#if !defined(NO_TRACELOG)
|
||||||
int traceDebugMsgs = 1;
|
static char buffer[128];
|
||||||
|
|
||||||
#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];
|
|
||||||
int traceDebugMsgs = 1;
|
int traceDebugMsgs = 1;
|
||||||
|
|
||||||
#ifdef DO_NOT_TRACE_DEBUG_MSGS
|
#ifdef DO_NOT_TRACE_DEBUG_MSGS
|
||||||
|
@ -146,8 +99,9 @@ void TraceLog(int msgType, const char *text, ...)
|
||||||
strcat(buffer, "\n");
|
strcat(buffer, "\n");
|
||||||
|
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, buffer);
|
va_start(args, text);
|
||||||
|
|
||||||
|
#if defined(PLATFORM_ANDROID)
|
||||||
switch(msgType)
|
switch(msgType)
|
||||||
{
|
{
|
||||||
case INFO: __android_log_vprint(ANDROID_LOG_INFO, "raylib", buffer, args); break;
|
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;
|
case DEBUG: if (traceDebugMsgs) __android_log_vprint(ANDROID_LOG_DEBUG, "raylib", buffer, args); break;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
if ((msgType != DEBUG) || ((msgType == DEBUG) && (traceDebugMsgs))) vprintf(buffer, args);
|
||||||
|
#endif
|
||||||
|
|
||||||
va_end(args);
|
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
|
// Initialize asset manager from android app
|
||||||
void InitAssetManager(AAssetManager *manager)
|
void InitAssetManager(AAssetManager *manager)
|
||||||
{
|
{
|
||||||
|
@ -199,23 +173,6 @@ const char *GetExtension(const char *fileName)
|
||||||
return (dot + 1);
|
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
|
// Module specific Functions Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
18
src/utils.h
18
src/utils.h
|
@ -43,19 +43,8 @@
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Types and Structures Definition
|
// Types and Structures Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
typedef enum { IMAGE = 0, SOUND, MODEL, TEXT, RAW } DataType;
|
|
||||||
|
|
||||||
typedef enum { INFO = 0, ERROR, WARNING, DEBUG, OTHER } TraceLogType;
|
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
|
#ifdef __cplusplus
|
||||||
extern "C" { // Prevents name mangling of functions
|
extern "C" { // Prevents name mangling of functions
|
||||||
#endif
|
#endif
|
||||||
|
@ -68,15 +57,14 @@ extern "C" { // Prevents name mangling of functions
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module Functions Declaration
|
// 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)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
|
||||||
void SaveBMP(const char *fileName, unsigned char *imgData, int width, int height, int compSize);
|
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);
|
void SavePNG(const char *fileName, unsigned char *imgData, int width, int height, int compSize);
|
||||||
#endif
|
#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)
|
#if defined(PLATFORM_ANDROID)
|
||||||
void InitAssetManager(AAssetManager *manager); // Initialize asset manager from android app
|
void InitAssetManager(AAssetManager *manager); // Initialize asset manager from android app
|
||||||
FILE *android_fopen(const char *fileName, const char *mode); // Replacement for fopen()
|
FILE *android_fopen(const char *fileName, const char *mode); // Replacement for fopen()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue