Update C sources
This commit is contained in:
parent
aabc97d1c2
commit
607adace28
71 changed files with 28187 additions and 15292 deletions
|
@ -28,16 +28,16 @@
|
|||
//------------------------------------------------------------------------------------
|
||||
// Module: core - Configuration Flags
|
||||
//------------------------------------------------------------------------------------
|
||||
// Camera module is included (camera.h) and multiple predefined cameras are available: free, 1st/3rd person, orbital
|
||||
// Camera module is included (rcamera.h) and multiple predefined cameras are available: free, 1st/3rd person, orbital
|
||||
#define SUPPORT_CAMERA_SYSTEM 1
|
||||
// Gestures module is included (gestures.h) to support gestures detection: tap, hold, swipe, drag
|
||||
// Gestures module is included (rgestures.h) to support gestures detection: tap, hold, swipe, drag
|
||||
#define SUPPORT_GESTURES_SYSTEM 1
|
||||
// Mouse gestures are directly mapped like touches and processed by gestures system
|
||||
#define SUPPORT_MOUSE_GESTURES 1
|
||||
// Reconfigure standard input to receive key inputs, works with SSH connection.
|
||||
#define SUPPORT_SSH_KEYBOARD_RPI 1
|
||||
// Draw a mouse pointer on screen
|
||||
#define SUPPORT_MOUSE_CURSOR_NATIVE 1
|
||||
//#define SUPPORT_MOUSE_CURSOR_POINT 1
|
||||
// Setting a higher resolution can improve the accuracy of time-out intervals in wait functions.
|
||||
// However, it can also reduce overall system performance, because the thread scheduler switches tasks more often.
|
||||
#define SUPPORT_WINMM_HIGHRES_TIMER 1
|
||||
|
@ -55,6 +55,12 @@
|
|||
#define SUPPORT_COMPRESSION_API 1
|
||||
// Support saving binary data automatically to a generated storage.data file. This file is managed internally.
|
||||
#define SUPPORT_DATA_STORAGE 1
|
||||
// Support automatic generated events, loading and recording of those events when required
|
||||
//#define SUPPORT_EVENTS_AUTOMATION 1
|
||||
// Support custom frame control, only for advance users
|
||||
// By default EndDrawing() does this job: draws everything + SwapScreenBuffer() + manage frame timming + PollInputEvents()
|
||||
// Enabling this flag allows manual control of the frame processes, use at your own risk
|
||||
//#define SUPPORT_CUSTOM_FRAME_CONTROL 1
|
||||
|
||||
// core: Configuration values
|
||||
//------------------------------------------------------------------------------------
|
||||
|
@ -67,7 +73,7 @@
|
|||
#define MAX_GAMEPADS 4 // Max number of gamepads supported
|
||||
#define MAX_GAMEPAD_AXIS 8 // Max number of axis supported (per gamepad)
|
||||
#define MAX_GAMEPAD_BUTTONS 32 // Max bumber of buttons supported (per gamepad)
|
||||
#define MAX_TOUCH_POINTS 10 // Maximum number of touch points supported
|
||||
#define MAX_TOUCH_POINTS 8 // Maximum number of touch points supported
|
||||
#define MAX_KEY_PRESSED_QUEUE 16 // Max number of characters in the key input queue
|
||||
|
||||
#define STORAGE_DATA_FILE "storage.data" // Automatic storage filename
|
||||
|
@ -78,33 +84,43 @@
|
|||
//------------------------------------------------------------------------------------
|
||||
// Module: rlgl - Configuration values
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
// Enable OpenGL Debug Context (only available on OpenGL 4.3)
|
||||
//#define RLGL_ENABLE_OPENGL_DEBUG_CONTEXT 1
|
||||
|
||||
// Show OpenGL extensions and capabilities detailed logs on init
|
||||
//#define SUPPORT_GL_DETAILS_INFO 1
|
||||
//#define RLGL_SHOW_GL_DETAILS_INFO 1
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
|
||||
#define DEFAULT_BATCH_BUFFER_ELEMENTS 8192 // Default internal render batch limits
|
||||
#elif defined(GRAPHICS_API_OPENGL_ES2)
|
||||
#define DEFAULT_BATCH_BUFFER_ELEMENTS 2048 // Default internal render batch limits
|
||||
#endif
|
||||
//#define RL_DEFAULT_BATCH_BUFFER_ELEMENTS 4096 // Default internal render batch elements limits
|
||||
#define RL_DEFAULT_BATCH_BUFFERS 1 // Default number of batch buffers (multi-buffering)
|
||||
#define RL_DEFAULT_BATCH_DRAWCALLS 256 // Default number of batch draw calls (by state changes: mode, texture)
|
||||
#define RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS 4 // Maximum number of textures units that can be activated on batch drawing (SetShaderValueTexture())
|
||||
|
||||
#define DEFAULT_BATCH_BUFFERS 1 // Default number of batch buffers (multi-buffering)
|
||||
#define DEFAULT_BATCH_DRAWCALLS 256 // Default number of batch draw calls (by state changes: mode, texture)
|
||||
#define RL_MAX_MATRIX_STACK_SIZE 32 // Maximum size of internal Matrix stack
|
||||
|
||||
#define MAX_MATRIX_STACK_SIZE 32 // Maximum size of internal Matrix stack
|
||||
#define MAX_MESH_VERTEX_BUFFERS 7 // Maximum vertex buffers (VBO) per mesh
|
||||
#define MAX_SHADER_LOCATIONS 32 // Maximum number of shader locations supported
|
||||
#define MAX_MATERIAL_MAPS 12 // Maximum number of shader maps supported
|
||||
#define RL_MAX_SHADER_LOCATIONS 32 // Maximum number of shader locations supported
|
||||
|
||||
#define RL_CULL_DISTANCE_NEAR 0.01 // Default projection matrix near cull distance
|
||||
#define RL_CULL_DISTANCE_FAR 1000.0 // Default projection matrix far cull distance
|
||||
|
||||
// Default shader vertex attribute names to set location points
|
||||
#define DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Binded by default to shader location: 0
|
||||
#define DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Binded by default to shader location: 1
|
||||
#define DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Binded by default to shader location: 2
|
||||
#define DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Binded by default to shader location: 3
|
||||
#define DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Binded by default to shader location: 4
|
||||
#define DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Binded by default to shader location: 5
|
||||
// NOTE: When a new shader is loaded, the following locations are tried to be set for convenience
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_POSITION "vertexPosition" // Binded by default to shader location: 0
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD "vertexTexCoord" // Binded by default to shader location: 1
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_NORMAL "vertexNormal" // Binded by default to shader location: 2
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR "vertexColor" // Binded by default to shader location: 3
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT "vertexTangent" // Binded by default to shader location: 4
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2 "vertexTexCoord2" // Binded by default to shader location: 5
|
||||
|
||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix
|
||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_VIEW "matView" // view matrix
|
||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_PROJECTION "matProjection" // projection matrix
|
||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_MODEL "matModel" // model matrix
|
||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_NORMAL "matNormal" // normal matrix (transpose(inverse(matModelView))
|
||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_COLOR "colDiffuse" // color diffuse (base tint color, multiplied by texture color)
|
||||
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE0 "texture0" // texture0 (texture slot active 0)
|
||||
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE1 "texture1" // texture1 (texture slot active 1)
|
||||
#define RL_DEFAULT_SHADER_SAMPLER2D_NAME_TEXTURE2 "texture2" // texture2 (texture slot active 2)
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
|
@ -159,7 +175,6 @@
|
|||
//------------------------------------------------------------------------------------
|
||||
#define MAX_TEXT_BUFFER_LENGTH 1024 // Size of internal static buffers used on some functions:
|
||||
// TextFormat(), TextSubtext(), TextToUpper(), TextToLower(), TextToPascal(), TextSplit()
|
||||
#define MAX_TEXT_UNICODE_CHARS 512 // Maximum number of unicode codepoints: GetCodepoints()
|
||||
#define MAX_TEXTSPLIT_COUNT 128 // Maximum number of substrings to split: TextSplit()
|
||||
|
||||
|
||||
|
@ -171,10 +186,15 @@
|
|||
#define SUPPORT_FILEFORMAT_MTL 1
|
||||
#define SUPPORT_FILEFORMAT_IQM 1
|
||||
#define SUPPORT_FILEFORMAT_GLTF 1
|
||||
#define SUPPORT_FILEFORMAT_VOX 1
|
||||
// Support procedural mesh generation functions, uses external par_shapes.h library
|
||||
// NOTE: Some generated meshes DO NOT include generated texture coordinates
|
||||
#define SUPPORT_MESH_GENERATION 1
|
||||
|
||||
// models: Configuration values
|
||||
//------------------------------------------------------------------------------------
|
||||
#define MAX_MATERIAL_MAPS 12 // Maximum number of shader maps supported
|
||||
#define MAX_MESH_VERTEX_BUFFERS 7 // Maximum vertex buffers (VBO) per mesh
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module: audio - Configuration Flags
|
||||
|
@ -208,4 +228,3 @@
|
|||
// utils: Configuration values
|
||||
//------------------------------------------------------------------------------------
|
||||
#define MAX_TRACELOG_MSG_LENGTH 128 // Max length of one trace-log message
|
||||
#define MAX_UWP_MESSAGES 512 // Max UWP messages to process
|
||||
|
|
208
raylib/external/cgltf.h
vendored
208
raylib/external/cgltf.h
vendored
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* cgltf - a single-file glTF 2.0 parser written in C99.
|
||||
*
|
||||
* Version: 1.10
|
||||
* Version: 1.11
|
||||
*
|
||||
* Website: https://github.com/jkuhlmann/cgltf
|
||||
*
|
||||
|
@ -234,6 +234,12 @@ typedef enum cgltf_light_type {
|
|||
cgltf_light_type_spot,
|
||||
} cgltf_light_type;
|
||||
|
||||
typedef enum cgltf_data_free_method {
|
||||
cgltf_data_free_method_none,
|
||||
cgltf_data_free_method_file_release,
|
||||
cgltf_data_free_method_memory_free,
|
||||
} cgltf_data_free_method;
|
||||
|
||||
typedef struct cgltf_extras {
|
||||
cgltf_size start_offset;
|
||||
cgltf_size end_offset;
|
||||
|
@ -250,6 +256,7 @@ typedef struct cgltf_buffer
|
|||
cgltf_size size;
|
||||
char* uri;
|
||||
void* data; /* loaded by cgltf_load_buffers */
|
||||
cgltf_data_free_method data_free_method;
|
||||
cgltf_extras extras;
|
||||
cgltf_size extensions_count;
|
||||
cgltf_extension* extensions;
|
||||
|
@ -372,6 +379,8 @@ typedef struct cgltf_texture
|
|||
char* name;
|
||||
cgltf_image* image;
|
||||
cgltf_sampler* sampler;
|
||||
cgltf_bool has_basisu;
|
||||
cgltf_image* basisu_image;
|
||||
cgltf_extras extras;
|
||||
cgltf_size extensions_count;
|
||||
cgltf_extension* extensions;
|
||||
|
@ -382,6 +391,7 @@ typedef struct cgltf_texture_transform
|
|||
cgltf_float offset[2];
|
||||
cgltf_float rotation;
|
||||
cgltf_float scale[2];
|
||||
cgltf_bool has_texcoord;
|
||||
cgltf_int texcoord;
|
||||
} cgltf_texture_transform;
|
||||
|
||||
|
@ -595,6 +605,7 @@ typedef struct cgltf_light {
|
|||
cgltf_float range;
|
||||
cgltf_float spot_inner_cone_angle;
|
||||
cgltf_float spot_outer_cone_angle;
|
||||
cgltf_extras extras;
|
||||
} cgltf_light;
|
||||
|
||||
struct cgltf_node {
|
||||
|
@ -768,6 +779,7 @@ cgltf_result cgltf_load_buffers(
|
|||
|
||||
cgltf_result cgltf_load_buffer_base64(const cgltf_options* options, cgltf_size size, const char* base64, void** out_data);
|
||||
|
||||
void cgltf_decode_string(char* string);
|
||||
void cgltf_decode_uri(char* uri);
|
||||
|
||||
cgltf_result cgltf_validate(cgltf_data* data);
|
||||
|
@ -813,7 +825,7 @@ cgltf_result cgltf_copy_extras_json(const cgltf_data* data, const cgltf_extras*
|
|||
#include <limits.h> /* For UINT_MAX etc */
|
||||
#include <float.h> /* For FLT_MAX */
|
||||
|
||||
#if !defined(CGLTF_MALLOC) || !defined(CGLTF_FREE) || !defined(CGLTF_ATOI) || !defined(CGLTF_ATOF)
|
||||
#if !defined(CGLTF_MALLOC) || !defined(CGLTF_FREE) || !defined(CGLTF_ATOI) || !defined(CGLTF_ATOF) || !defined(CGLTF_ATOLL)
|
||||
#include <stdlib.h> /* For malloc, free, atoi, atof */
|
||||
#endif
|
||||
|
||||
|
@ -883,6 +895,9 @@ static const uint32_t GlbMagicBinChunk = 0x004E4942;
|
|||
#ifndef CGLTF_ATOF
|
||||
#define CGLTF_ATOF(str) atof(str)
|
||||
#endif
|
||||
#ifndef CGLTF_ATOLL
|
||||
#define CGLTF_ATOLL(str) atoll(str)
|
||||
#endif
|
||||
#ifndef CGLTF_VALIDATE_ENABLE_ASSERTS
|
||||
#define CGLTF_VALIDATE_ENABLE_ASSERTS 0
|
||||
#endif
|
||||
|
@ -932,7 +947,12 @@ static cgltf_result cgltf_default_file_read(const struct cgltf_memory_options* m
|
|||
{
|
||||
fseek(file, 0, SEEK_END);
|
||||
|
||||
#ifdef _WIN32
|
||||
__int64 length = _ftelli64(file);
|
||||
#else
|
||||
long length = ftell(file);
|
||||
#endif
|
||||
|
||||
if (length < 0)
|
||||
{
|
||||
fclose(file);
|
||||
|
@ -1120,8 +1140,8 @@ cgltf_result cgltf_parse_file(const cgltf_options* options, const char* path, cg
|
|||
return cgltf_result_invalid_options;
|
||||
}
|
||||
|
||||
void (*memory_free)(void*, void*) = options->memory.free ? options->memory.free : &cgltf_default_free;
|
||||
cgltf_result (*file_read)(const struct cgltf_memory_options*, const struct cgltf_file_options*, const char*, cgltf_size*, void**) = options->file.read ? options->file.read : &cgltf_default_file_read;
|
||||
void (*file_release)(const struct cgltf_memory_options*, const struct cgltf_file_options*, void* data) = options->file.release ? options->file.release : cgltf_default_file_release;
|
||||
|
||||
void* file_data = NULL;
|
||||
cgltf_size file_size = 0;
|
||||
|
@ -1135,7 +1155,7 @@ cgltf_result cgltf_parse_file(const cgltf_options* options, const char* path, cg
|
|||
|
||||
if (result != cgltf_result_success)
|
||||
{
|
||||
memory_free(options->memory.user_data, file_data);
|
||||
file_release(&options->memory, &options->file, file_data);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1246,6 +1266,72 @@ static int cgltf_unhex(char ch)
|
|||
-1;
|
||||
}
|
||||
|
||||
void cgltf_decode_string(char* string)
|
||||
{
|
||||
char* read = strchr(string, '\\');
|
||||
if (read == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
char* write = string;
|
||||
char* last = string;
|
||||
|
||||
while (read)
|
||||
{
|
||||
// Copy characters since last escaped sequence
|
||||
cgltf_size written = read - last;
|
||||
strncpy(write, last, written);
|
||||
write += written;
|
||||
|
||||
// jsmn already checked that all escape sequences are valid
|
||||
++read;
|
||||
switch (*read++)
|
||||
{
|
||||
case '\"': *write++ = '\"'; break;
|
||||
case '/': *write++ = '/'; break;
|
||||
case '\\': *write++ = '\\'; break;
|
||||
case 'b': *write++ = '\b'; break;
|
||||
case 'f': *write++ = '\f'; break;
|
||||
case 'r': *write++ = '\r'; break;
|
||||
case 'n': *write++ = '\n'; break;
|
||||
case 't': *write++ = '\t'; break;
|
||||
case 'u':
|
||||
{
|
||||
// UCS-2 codepoint \uXXXX to UTF-8
|
||||
int character = 0;
|
||||
for (cgltf_size i = 0; i < 4; ++i)
|
||||
{
|
||||
character = (character << 4) + cgltf_unhex(*read++);
|
||||
}
|
||||
|
||||
if (character <= 0x7F)
|
||||
{
|
||||
*write++ = character & 0xFF;
|
||||
}
|
||||
else if (character <= 0x7FF)
|
||||
{
|
||||
*write++ = 0xC0 | ((character >> 6) & 0xFF);
|
||||
*write++ = 0x80 | (character & 0x3F);
|
||||
}
|
||||
else
|
||||
{
|
||||
*write++ = 0xE0 | ((character >> 12) & 0xFF);
|
||||
*write++ = 0x80 | ((character >> 6) & 0x3F);
|
||||
*write++ = 0x80 | (character & 0x3F);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
last = read;
|
||||
read = strchr(read, '\\');
|
||||
}
|
||||
|
||||
strcpy(write, last);
|
||||
}
|
||||
|
||||
void cgltf_decode_uri(char* uri)
|
||||
{
|
||||
char* write = uri;
|
||||
|
@ -1291,6 +1377,7 @@ cgltf_result cgltf_load_buffers(const cgltf_options* options, cgltf_data* data,
|
|||
}
|
||||
|
||||
data->buffers[0].data = (void*)data->bin;
|
||||
data->buffers[0].data_free_method = cgltf_data_free_method_none;
|
||||
}
|
||||
|
||||
for (cgltf_size i = 0; i < data->buffers_count; ++i)
|
||||
|
@ -1314,6 +1401,7 @@ cgltf_result cgltf_load_buffers(const cgltf_options* options, cgltf_data* data,
|
|||
if (comma && comma - uri >= 7 && strncmp(comma - 7, ";base64", 7) == 0)
|
||||
{
|
||||
cgltf_result res = cgltf_load_buffer_base64(options, data->buffers[i].size, comma + 1, &data->buffers[i].data);
|
||||
data->buffers[i].data_free_method = cgltf_data_free_method_memory_free;
|
||||
|
||||
if (res != cgltf_result_success)
|
||||
{
|
||||
|
@ -1328,6 +1416,7 @@ cgltf_result cgltf_load_buffers(const cgltf_options* options, cgltf_data* data,
|
|||
else if (strstr(uri, "://") == NULL && gltf_path)
|
||||
{
|
||||
cgltf_result res = cgltf_load_buffer_file(options, data->buffers[i].size, uri, gltf_path, &data->buffers[i].data);
|
||||
data->buffers[i].data_free_method = cgltf_data_free_method_file_release;
|
||||
|
||||
if (res != cgltf_result_success)
|
||||
{
|
||||
|
@ -1655,10 +1744,15 @@ void cgltf_free(cgltf_data* data)
|
|||
{
|
||||
data->memory.free(data->memory.user_data, data->buffers[i].name);
|
||||
|
||||
if (data->buffers[i].data != data->bin)
|
||||
if (data->buffers[i].data_free_method == cgltf_data_free_method_file_release)
|
||||
{
|
||||
file_release(&data->memory, &data->file, data->buffers[i].data);
|
||||
}
|
||||
else if (data->buffers[i].data_free_method == cgltf_data_free_method_memory_free)
|
||||
{
|
||||
data->memory.free(data->memory.user_data, data->buffers[i].data);
|
||||
}
|
||||
|
||||
data->memory.free(data->memory.user_data, data->buffers[i].uri);
|
||||
|
||||
cgltf_free_extensions(data, data->buffers[i].extensions, data->buffers[i].extensions_count);
|
||||
|
@ -2259,6 +2353,7 @@ cgltf_size cgltf_accessor_read_index(const cgltf_accessor* accessor, cgltf_size
|
|||
#define CGLTF_ERROR_LEGACY -3
|
||||
|
||||
#define CGLTF_CHECK_TOKTYPE(tok_, type_) if ((tok_).type != (type_)) { return CGLTF_ERROR_JSON; }
|
||||
#define CGLTF_CHECK_TOKTYPE_RETTYPE(tok_, type_, ret_) if ((tok_).type != (type_)) { return (ret_)CGLTF_ERROR_JSON; }
|
||||
#define CGLTF_CHECK_KEY(tok_) if ((tok_).type != JSMN_STRING || (tok_).size == 0) { return CGLTF_ERROR_JSON; } /* checking size for 0 verifies that a value follows the key */
|
||||
|
||||
#define CGLTF_PTRINDEX(type, idx) (type*)((cgltf_size)idx + 1)
|
||||
|
@ -2283,6 +2378,16 @@ static int cgltf_json_to_int(jsmntok_t const* tok, const uint8_t* json_chunk)
|
|||
return CGLTF_ATOI(tmp);
|
||||
}
|
||||
|
||||
static cgltf_size cgltf_json_to_size(jsmntok_t const* tok, const uint8_t* json_chunk)
|
||||
{
|
||||
CGLTF_CHECK_TOKTYPE_RETTYPE(*tok, JSMN_PRIMITIVE, cgltf_size);
|
||||
char tmp[128];
|
||||
int size = (cgltf_size)(tok->end - tok->start) < sizeof(tmp) ? tok->end - tok->start : (int)(sizeof(tmp) - 1);
|
||||
strncpy(tmp, (const char*)json_chunk + tok->start, size);
|
||||
tmp[size] = 0;
|
||||
return (cgltf_size)CGLTF_ATOLL(tmp);
|
||||
}
|
||||
|
||||
static cgltf_float cgltf_json_to_float(jsmntok_t const* tok, const uint8_t* json_chunk)
|
||||
{
|
||||
CGLTF_CHECK_TOKTYPE(*tok, JSMN_PRIMITIVE);
|
||||
|
@ -3024,7 +3129,7 @@ static int cgltf_parse_json_accessor_sparse(cgltf_options* options, jsmntok_t co
|
|||
else if (cgltf_json_strcmp(tokens+i, json_chunk, "byteOffset") == 0)
|
||||
{
|
||||
++i;
|
||||
out_sparse->indices_byte_offset = cgltf_json_to_int(tokens + i, json_chunk);
|
||||
out_sparse->indices_byte_offset = cgltf_json_to_size(tokens + i, json_chunk);
|
||||
++i;
|
||||
}
|
||||
else if (cgltf_json_strcmp(tokens+i, json_chunk, "componentType") == 0)
|
||||
|
@ -3073,7 +3178,7 @@ static int cgltf_parse_json_accessor_sparse(cgltf_options* options, jsmntok_t co
|
|||
else if (cgltf_json_strcmp(tokens+i, json_chunk, "byteOffset") == 0)
|
||||
{
|
||||
++i;
|
||||
out_sparse->values_byte_offset = cgltf_json_to_int(tokens + i, json_chunk);
|
||||
out_sparse->values_byte_offset = cgltf_json_to_size(tokens + i, json_chunk);
|
||||
++i;
|
||||
}
|
||||
else if (cgltf_json_strcmp(tokens + i, json_chunk, "extras") == 0)
|
||||
|
@ -3142,7 +3247,7 @@ static int cgltf_parse_json_accessor(cgltf_options* options, jsmntok_t const* to
|
|||
{
|
||||
++i;
|
||||
out_accessor->offset =
|
||||
cgltf_json_to_int(tokens+i, json_chunk);
|
||||
cgltf_json_to_size(tokens+i, json_chunk);
|
||||
++i;
|
||||
}
|
||||
else if (cgltf_json_strcmp(tokens+i, json_chunk, "componentType") == 0)
|
||||
|
@ -3268,6 +3373,7 @@ static int cgltf_parse_json_texture_transform(jsmntok_t const* tokens, int i, co
|
|||
else if (cgltf_json_strcmp(tokens + i, json_chunk, "texCoord") == 0)
|
||||
{
|
||||
++i;
|
||||
out_texture_transform->has_texcoord = 1;
|
||||
out_texture_transform->texcoord = cgltf_json_to_int(tokens + i, json_chunk);
|
||||
++i;
|
||||
}
|
||||
|
@ -3885,7 +3991,62 @@ static int cgltf_parse_json_texture(cgltf_options* options, jsmntok_t const* tok
|
|||
}
|
||||
else if (cgltf_json_strcmp(tokens + i, json_chunk, "extensions") == 0)
|
||||
{
|
||||
i = cgltf_parse_json_unprocessed_extensions(options, tokens, i, json_chunk, &out_texture->extensions_count, &out_texture->extensions);
|
||||
++i;
|
||||
|
||||
CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
|
||||
if (out_texture->extensions)
|
||||
{
|
||||
return CGLTF_ERROR_JSON;
|
||||
}
|
||||
|
||||
int extensions_size = tokens[i].size;
|
||||
++i;
|
||||
out_texture->extensions = (cgltf_extension*)cgltf_calloc(options, sizeof(cgltf_extension), extensions_size);
|
||||
out_texture->extensions_count = 0;
|
||||
|
||||
if (!out_texture->extensions)
|
||||
{
|
||||
return CGLTF_ERROR_NOMEM;
|
||||
}
|
||||
|
||||
for (int k = 0; k < extensions_size; ++k)
|
||||
{
|
||||
CGLTF_CHECK_KEY(tokens[i]);
|
||||
|
||||
if (cgltf_json_strcmp(tokens + i, json_chunk, "KHR_texture_basisu") == 0)
|
||||
{
|
||||
out_texture->has_basisu = 1;
|
||||
++i;
|
||||
CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
|
||||
int num_properties = tokens[i].size;
|
||||
++i;
|
||||
|
||||
for (int t = 0; t < num_properties; ++t)
|
||||
{
|
||||
CGLTF_CHECK_KEY(tokens[i]);
|
||||
|
||||
if (cgltf_json_strcmp(tokens + i, json_chunk, "source") == 0)
|
||||
{
|
||||
++i;
|
||||
out_texture->basisu_image = CGLTF_PTRINDEX(cgltf_image, cgltf_json_to_int(tokens + i, json_chunk));
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
i = cgltf_skip_json(tokens, i + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
i = cgltf_parse_json_unprocessed_extension(options, tokens, i, json_chunk, &(out_texture->extensions[out_texture->extensions_count++]));
|
||||
}
|
||||
|
||||
if (i < 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -4192,19 +4353,19 @@ static int cgltf_parse_json_meshopt_compression(cgltf_options* options, jsmntok_
|
|||
else if (cgltf_json_strcmp(tokens+i, json_chunk, "byteOffset") == 0)
|
||||
{
|
||||
++i;
|
||||
out_meshopt_compression->offset = cgltf_json_to_int(tokens+i, json_chunk);
|
||||
out_meshopt_compression->offset = cgltf_json_to_size(tokens+i, json_chunk);
|
||||
++i;
|
||||
}
|
||||
else if (cgltf_json_strcmp(tokens+i, json_chunk, "byteLength") == 0)
|
||||
{
|
||||
++i;
|
||||
out_meshopt_compression->size = cgltf_json_to_int(tokens+i, json_chunk);
|
||||
out_meshopt_compression->size = cgltf_json_to_size(tokens+i, json_chunk);
|
||||
++i;
|
||||
}
|
||||
else if (cgltf_json_strcmp(tokens+i, json_chunk, "byteStride") == 0)
|
||||
{
|
||||
++i;
|
||||
out_meshopt_compression->stride = cgltf_json_to_int(tokens+i, json_chunk);
|
||||
out_meshopt_compression->stride = cgltf_json_to_size(tokens+i, json_chunk);
|
||||
++i;
|
||||
}
|
||||
else if (cgltf_json_strcmp(tokens+i, json_chunk, "count") == 0)
|
||||
|
@ -4290,21 +4451,21 @@ static int cgltf_parse_json_buffer_view(cgltf_options* options, jsmntok_t const*
|
|||
{
|
||||
++i;
|
||||
out_buffer_view->offset =
|
||||
cgltf_json_to_int(tokens+i, json_chunk);
|
||||
cgltf_json_to_size(tokens+i, json_chunk);
|
||||
++i;
|
||||
}
|
||||
else if (cgltf_json_strcmp(tokens+i, json_chunk, "byteLength") == 0)
|
||||
{
|
||||
++i;
|
||||
out_buffer_view->size =
|
||||
cgltf_json_to_int(tokens+i, json_chunk);
|
||||
cgltf_json_to_size(tokens+i, json_chunk);
|
||||
++i;
|
||||
}
|
||||
else if (cgltf_json_strcmp(tokens+i, json_chunk, "byteStride") == 0)
|
||||
{
|
||||
++i;
|
||||
out_buffer_view->stride =
|
||||
cgltf_json_to_int(tokens+i, json_chunk);
|
||||
cgltf_json_to_size(tokens+i, json_chunk);
|
||||
++i;
|
||||
}
|
||||
else if (cgltf_json_strcmp(tokens+i, json_chunk, "target") == 0)
|
||||
|
@ -4422,7 +4583,7 @@ static int cgltf_parse_json_buffer(cgltf_options* options, jsmntok_t const* toke
|
|||
{
|
||||
++i;
|
||||
out_buffer->size =
|
||||
cgltf_json_to_int(tokens+i, json_chunk);
|
||||
cgltf_json_to_size(tokens+i, json_chunk);
|
||||
++i;
|
||||
}
|
||||
else if (cgltf_json_strcmp(tokens+i, json_chunk, "uri") == 0)
|
||||
|
@ -4737,6 +4898,14 @@ static int cgltf_parse_json_light(cgltf_options* options, jsmntok_t const* token
|
|||
{
|
||||
CGLTF_CHECK_TOKTYPE(tokens[i], JSMN_OBJECT);
|
||||
|
||||
out_light->color[0] = 1.f;
|
||||
out_light->color[1] = 1.f;
|
||||
out_light->color[2] = 1.f;
|
||||
out_light->intensity = 1.f;
|
||||
|
||||
out_light->spot_inner_cone_angle = 0.f;
|
||||
out_light->spot_outer_cone_angle = 3.1415926535f / 4.0f;
|
||||
|
||||
int size = tokens[i].size;
|
||||
++i;
|
||||
|
||||
|
@ -4817,6 +4986,10 @@ static int cgltf_parse_json_light(cgltf_options* options, jsmntok_t const* token
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (cgltf_json_strcmp(tokens + i, json_chunk, "extras") == 0)
|
||||
{
|
||||
i = cgltf_parse_json_extras(tokens, i + 1, json_chunk, &out_light->extras);
|
||||
}
|
||||
else
|
||||
{
|
||||
i = cgltf_skip_json(tokens, i+1);
|
||||
|
@ -5851,6 +6024,7 @@ static int cgltf_fixup_pointers(cgltf_data* data)
|
|||
for (cgltf_size i = 0; i < data->textures_count; ++i)
|
||||
{
|
||||
CGLTF_PTRFIXUP(data->textures[i].image, data->images, data->images_count);
|
||||
CGLTF_PTRFIXUP(data->textures[i].basisu_image, data->images, data->images_count);
|
||||
CGLTF_PTRFIXUP(data->textures[i].sampler, data->samplers, data->samplers_count);
|
||||
}
|
||||
|
||||
|
@ -6305,7 +6479,7 @@ static void jsmn_init(jsmn_parser *parser) {
|
|||
|
||||
/* cgltf is distributed under MIT license:
|
||||
*
|
||||
* Copyright (c) 2018 Johannes Kuhlmann
|
||||
* Copyright (c) 2018-2021 Johannes Kuhlmann
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
|
14
raylib/external/dr_flac.h
vendored
14
raylib/external/dr_flac.h
vendored
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
FLAC audio decoder. Choice of public domain or MIT-0. See license statements at the end of this file.
|
||||
dr_flac - v0.12.29 - 2021-04-02
|
||||
dr_flac - v0.12.31 - 2021-08-16
|
||||
|
||||
David Reid - mackron@gmail.com
|
||||
|
||||
|
@ -232,7 +232,7 @@ extern "C" {
|
|||
|
||||
#define DRFLAC_VERSION_MAJOR 0
|
||||
#define DRFLAC_VERSION_MINOR 12
|
||||
#define DRFLAC_VERSION_REVISION 29
|
||||
#define DRFLAC_VERSION_REVISION 31
|
||||
#define DRFLAC_VERSION_STRING DRFLAC_XSTRINGIFY(DRFLAC_VERSION_MAJOR) "." DRFLAC_XSTRINGIFY(DRFLAC_VERSION_MINOR) "." DRFLAC_XSTRINGIFY(DRFLAC_VERSION_REVISION)
|
||||
|
||||
#include <stddef.h> /* For size_t. */
|
||||
|
@ -261,7 +261,7 @@ typedef unsigned int drflac_uint32;
|
|||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#endif
|
||||
#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
|
||||
#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(_M_ARM64) || defined(__powerpc64__)
|
||||
typedef drflac_uint64 drflac_uintptr;
|
||||
#else
|
||||
typedef drflac_uint32 drflac_uintptr;
|
||||
|
@ -11516,7 +11516,7 @@ static type* drflac__full_read_and_close_ ## extension (drflac* pFlac, unsigned
|
|||
DRFLAC_ZERO_MEMORY(pSampleData + (totalPCMFrameCount*pFlac->channels), (size_t)(sampleDataBufferSize - totalPCMFrameCount*pFlac->channels*sizeof(type))); \
|
||||
} else { \
|
||||
drflac_uint64 dataSize = totalPCMFrameCount*pFlac->channels*sizeof(type); \
|
||||
if (dataSize > DRFLAC_SIZE_MAX) { \
|
||||
if (dataSize > (drflac_uint64)DRFLAC_SIZE_MAX) { \
|
||||
goto on_error; /* The decoded data is too big. */ \
|
||||
} \
|
||||
\
|
||||
|
@ -11851,6 +11851,12 @@ DRFLAC_API drflac_bool32 drflac_next_cuesheet_track(drflac_cuesheet_track_iterat
|
|||
/*
|
||||
REVISION HISTORY
|
||||
================
|
||||
v0.12.31 - 2021-08-16
|
||||
- Silence some warnings.
|
||||
|
||||
v0.12.30 - 2021-07-31
|
||||
- Fix platform detection for ARM64.
|
||||
|
||||
v0.12.29 - 2021-04-02
|
||||
- Fix a bug where the running PCM frame index is set to an invalid value when over-seeking.
|
||||
- Fix a decoding error due to an incorrect validation check.
|
||||
|
|
135
raylib/external/dr_mp3.h
vendored
135
raylib/external/dr_mp3.h
vendored
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
MP3 audio decoder. Choice of public domain or MIT-0. See license statements at the end of this file.
|
||||
dr_mp3 - v0.6.27 - 2021-02-21
|
||||
dr_mp3 - v0.6.31 - 2021-08-22
|
||||
|
||||
David Reid - mackron@gmail.com
|
||||
|
||||
|
@ -95,7 +95,7 @@ extern "C" {
|
|||
|
||||
#define DRMP3_VERSION_MAJOR 0
|
||||
#define DRMP3_VERSION_MINOR 6
|
||||
#define DRMP3_VERSION_REVISION 27
|
||||
#define DRMP3_VERSION_REVISION 31
|
||||
#define DRMP3_VERSION_STRING DRMP3_XSTRINGIFY(DRMP3_VERSION_MAJOR) "." DRMP3_XSTRINGIFY(DRMP3_VERSION_MINOR) "." DRMP3_XSTRINGIFY(DRMP3_VERSION_REVISION)
|
||||
|
||||
#include <stddef.h> /* For size_t. */
|
||||
|
@ -124,7 +124,7 @@ typedef unsigned int drmp3_uint32;
|
|||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#endif
|
||||
#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
|
||||
#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || defined (_M_IA64) || defined(__aarch64__) || defined(_M_ARM64) || defined(__powerpc64__)
|
||||
typedef drmp3_uint64 drmp3_uintptr;
|
||||
#else
|
||||
typedef drmp3_uint32 drmp3_uintptr;
|
||||
|
@ -701,7 +701,7 @@ static int drmp3_have_simd(void)
|
|||
|
||||
#if defined(__ARM_ARCH) && (__ARM_ARCH >= 6) && !defined(__aarch64__) && !defined(_M_ARM64)
|
||||
#define DRMP3_HAVE_ARMV6 1
|
||||
static __inline__ __attribute__((always_inline)) drmp3_int32 drmp3_clip_int16_arm(int32_t a)
|
||||
static __inline__ __attribute__((always_inline)) drmp3_int32 drmp3_clip_int16_arm(drmp3_int32 a)
|
||||
{
|
||||
drmp3_int32 x = 0;
|
||||
__asm__ ("ssat %0, #16, %1" : "=r"(x) : "r"(a));
|
||||
|
@ -712,6 +712,31 @@ static __inline__ __attribute__((always_inline)) drmp3_int32 drmp3_clip_int16_ar
|
|||
#endif
|
||||
|
||||
|
||||
/* Standard library stuff. */
|
||||
#ifndef DRMP3_ASSERT
|
||||
#include <assert.h>
|
||||
#define DRMP3_ASSERT(expression) assert(expression)
|
||||
#endif
|
||||
#ifndef DRMP3_COPY_MEMORY
|
||||
#define DRMP3_COPY_MEMORY(dst, src, sz) memcpy((dst), (src), (sz))
|
||||
#endif
|
||||
#ifndef DRMP3_MOVE_MEMORY
|
||||
#define DRMP3_MOVE_MEMORY(dst, src, sz) memmove((dst), (src), (sz))
|
||||
#endif
|
||||
#ifndef DRMP3_ZERO_MEMORY
|
||||
#define DRMP3_ZERO_MEMORY(p, sz) memset((p), 0, (sz))
|
||||
#endif
|
||||
#define DRMP3_ZERO_OBJECT(p) DRMP3_ZERO_MEMORY((p), sizeof(*(p)))
|
||||
#ifndef DRMP3_MALLOC
|
||||
#define DRMP3_MALLOC(sz) malloc((sz))
|
||||
#endif
|
||||
#ifndef DRMP3_REALLOC
|
||||
#define DRMP3_REALLOC(p, sz) realloc((p), (sz))
|
||||
#endif
|
||||
#ifndef DRMP3_FREE
|
||||
#define DRMP3_FREE(p) free((p))
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const drmp3_uint8 *buf;
|
||||
|
@ -978,7 +1003,7 @@ static int drmp3_L12_dequantize_granule(float *grbuf, drmp3_bs *bs, drmp3_L12_sc
|
|||
static void drmp3_L12_apply_scf_384(drmp3_L12_scale_info *sci, const float *scf, float *dst)
|
||||
{
|
||||
int i, k;
|
||||
memcpy(dst + 576 + sci->stereo_bands*18, dst + sci->stereo_bands*18, (sci->total_bands - sci->stereo_bands)*18*sizeof(float));
|
||||
DRMP3_COPY_MEMORY(dst + 576 + sci->stereo_bands*18, dst + sci->stereo_bands*18, (sci->total_bands - sci->stereo_bands)*18*sizeof(float));
|
||||
for (i = 0; i < sci->total_bands; i++, dst += 18, scf += 6)
|
||||
{
|
||||
for (k = 0; k < 12; k++)
|
||||
|
@ -1123,14 +1148,14 @@ static void drmp3_L3_read_scalefactors(drmp3_uint8 *scf, drmp3_uint8 *ist_pos, c
|
|||
int cnt = scf_count[i];
|
||||
if (scfsi & 8)
|
||||
{
|
||||
memcpy(scf, ist_pos, cnt);
|
||||
DRMP3_COPY_MEMORY(scf, ist_pos, cnt);
|
||||
} else
|
||||
{
|
||||
int bits = scf_size[i];
|
||||
if (!bits)
|
||||
{
|
||||
memset(scf, 0, cnt);
|
||||
memset(ist_pos, 0, cnt);
|
||||
DRMP3_ZERO_MEMORY(scf, cnt);
|
||||
DRMP3_ZERO_MEMORY(ist_pos, cnt);
|
||||
} else
|
||||
{
|
||||
int max_scf = (scfsi < 0) ? (1 << bits) - 1 : -1;
|
||||
|
@ -1390,13 +1415,23 @@ static void drmp3_L3_midside_stereo(float *left, int n)
|
|||
int i = 0;
|
||||
float *right = left + 576;
|
||||
#if DRMP3_HAVE_SIMD
|
||||
if (drmp3_have_simd()) for (; i < n - 3; i += 4)
|
||||
if (drmp3_have_simd())
|
||||
{
|
||||
for (; i < n - 3; i += 4)
|
||||
{
|
||||
drmp3_f4 vl = DRMP3_VLD(left + i);
|
||||
drmp3_f4 vr = DRMP3_VLD(right + i);
|
||||
DRMP3_VSTORE(left + i, DRMP3_VADD(vl, vr));
|
||||
DRMP3_VSTORE(right + i, DRMP3_VSUB(vl, vr));
|
||||
}
|
||||
#ifdef __GNUC__
|
||||
/* Workaround for spurious -Waggressive-loop-optimizations warning from gcc.
|
||||
* For more info see: https://github.com/lieff/minimp3/issues/88
|
||||
*/
|
||||
if (__builtin_constant_p(n % 4 == 0) && n % 4 == 0)
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
for (; i < n; i++)
|
||||
{
|
||||
|
@ -1505,7 +1540,7 @@ static void drmp3_L3_reorder(float *grbuf, float *scratch, const drmp3_uint8 *sf
|
|||
*dst++ = src[2*len];
|
||||
}
|
||||
}
|
||||
memcpy(grbuf, scratch, (dst - scratch)*sizeof(float));
|
||||
DRMP3_COPY_MEMORY(grbuf, scratch, (dst - scratch)*sizeof(float));
|
||||
}
|
||||
|
||||
static void drmp3_L3_antialias(float *grbuf, int nbands)
|
||||
|
@ -1674,8 +1709,8 @@ static void drmp3_L3_imdct_short(float *grbuf, float *overlap, int nbands)
|
|||
for (;nbands > 0; nbands--, overlap += 9, grbuf += 18)
|
||||
{
|
||||
float tmp[18];
|
||||
memcpy(tmp, grbuf, sizeof(tmp));
|
||||
memcpy(grbuf, overlap, 6*sizeof(float));
|
||||
DRMP3_COPY_MEMORY(tmp, grbuf, sizeof(tmp));
|
||||
DRMP3_COPY_MEMORY(grbuf, overlap, 6*sizeof(float));
|
||||
drmp3_L3_imdct12(tmp, grbuf + 6, overlap + 6);
|
||||
drmp3_L3_imdct12(tmp + 1, grbuf + 12, overlap + 6);
|
||||
drmp3_L3_imdct12(tmp + 2, overlap, overlap + 6);
|
||||
|
@ -1719,7 +1754,7 @@ static void drmp3_L3_save_reservoir(drmp3dec *h, drmp3dec_scratch *s)
|
|||
}
|
||||
if (remains > 0)
|
||||
{
|
||||
memmove(h->reserv_buf, s->maindata + pos, remains);
|
||||
DRMP3_MOVE_MEMORY(h->reserv_buf, s->maindata + pos, remains);
|
||||
}
|
||||
h->reserv = remains;
|
||||
}
|
||||
|
@ -1728,8 +1763,8 @@ static int drmp3_L3_restore_reservoir(drmp3dec *h, drmp3_bs *bs, drmp3dec_scratc
|
|||
{
|
||||
int frame_bytes = (bs->limit - bs->pos)/8;
|
||||
int bytes_have = DRMP3_MIN(h->reserv, main_data_begin);
|
||||
memcpy(s->maindata, h->reserv_buf + DRMP3_MAX(0, h->reserv - main_data_begin), DRMP3_MIN(h->reserv, main_data_begin));
|
||||
memcpy(s->maindata + bytes_have, bs->buf + bs->pos/8, frame_bytes);
|
||||
DRMP3_COPY_MEMORY(s->maindata, h->reserv_buf + DRMP3_MAX(0, h->reserv - main_data_begin), DRMP3_MIN(h->reserv, main_data_begin));
|
||||
DRMP3_COPY_MEMORY(s->maindata + bytes_have, bs->buf + bs->pos/8, frame_bytes);
|
||||
drmp3_bs_init(&s->bs, s->maindata, bytes_have + frame_bytes);
|
||||
return h->reserv >= main_data_begin;
|
||||
}
|
||||
|
@ -2136,7 +2171,7 @@ static void drmp3d_synth_granule(float *qmf_state, float *grbuf, int nbands, int
|
|||
drmp3d_DCT_II(grbuf + 576*i, nbands);
|
||||
}
|
||||
|
||||
memcpy(lins, qmf_state, sizeof(float)*15*64);
|
||||
DRMP3_COPY_MEMORY(lins, qmf_state, sizeof(float)*15*64);
|
||||
|
||||
for (i = 0; i < nbands; i += 2)
|
||||
{
|
||||
|
@ -2152,7 +2187,7 @@ static void drmp3d_synth_granule(float *qmf_state, float *grbuf, int nbands, int
|
|||
} else
|
||||
#endif
|
||||
{
|
||||
memcpy(qmf_state, lins + nbands*64, sizeof(float)*15*64);
|
||||
DRMP3_COPY_MEMORY(qmf_state, lins + nbands*64, sizeof(float)*15*64);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2230,7 +2265,7 @@ DRMP3_API int drmp3dec_decode_frame(drmp3dec *dec, const drmp3_uint8 *mp3, int m
|
|||
}
|
||||
if (!frame_size)
|
||||
{
|
||||
memset(dec, 0, sizeof(drmp3dec));
|
||||
DRMP3_ZERO_MEMORY(dec, sizeof(drmp3dec));
|
||||
i = drmp3d_find_frame(mp3, mp3_bytes, &dec->free_format_bytes, &frame_size);
|
||||
if (!frame_size || i + frame_size > mp3_bytes)
|
||||
{
|
||||
|
@ -2240,7 +2275,7 @@ DRMP3_API int drmp3dec_decode_frame(drmp3dec *dec, const drmp3_uint8 *mp3, int m
|
|||
}
|
||||
|
||||
hdr = mp3 + i;
|
||||
memcpy(dec->header, hdr, DRMP3_HDR_SIZE);
|
||||
DRMP3_COPY_MEMORY(dec->header, hdr, DRMP3_HDR_SIZE);
|
||||
info->frame_bytes = i + frame_size;
|
||||
info->channels = DRMP3_HDR_IS_MONO(hdr) ? 1 : 2;
|
||||
info->hz = drmp3_hdr_sample_rate_hz(hdr);
|
||||
|
@ -2266,7 +2301,7 @@ DRMP3_API int drmp3dec_decode_frame(drmp3dec *dec, const drmp3_uint8 *mp3, int m
|
|||
{
|
||||
for (igr = 0; igr < (DRMP3_HDR_TEST_MPEG1(hdr) ? 2 : 1); igr++, pcm = DRMP3_OFFSET_PTR(pcm, sizeof(drmp3d_sample_t)*576*info->channels))
|
||||
{
|
||||
memset(scratch.grbuf[0], 0, 576*2*sizeof(float));
|
||||
DRMP3_ZERO_MEMORY(scratch.grbuf[0], 576*2*sizeof(float));
|
||||
drmp3_L3_decode(dec, &scratch, scratch.gr_info + igr*info->channels, info->channels);
|
||||
drmp3d_synth_granule(dec->qmf_state, scratch.grbuf[0], 18, info->channels, (drmp3d_sample_t*)pcm, scratch.syn[0]);
|
||||
}
|
||||
|
@ -2285,7 +2320,7 @@ DRMP3_API int drmp3dec_decode_frame(drmp3dec *dec, const drmp3_uint8 *mp3, int m
|
|||
|
||||
drmp3_L12_read_scale_info(hdr, bs_frame, sci);
|
||||
|
||||
memset(scratch.grbuf[0], 0, 576*2*sizeof(float));
|
||||
DRMP3_ZERO_MEMORY(scratch.grbuf[0], 576*2*sizeof(float));
|
||||
for (i = 0, igr = 0; igr < 3; igr++)
|
||||
{
|
||||
if (12 == (i += drmp3_L12_dequantize_granule(scratch.grbuf[0] + i, bs_frame, sci, info->layer | 1)))
|
||||
|
@ -2293,7 +2328,7 @@ DRMP3_API int drmp3dec_decode_frame(drmp3dec *dec, const drmp3_uint8 *mp3, int m
|
|||
i = 0;
|
||||
drmp3_L12_apply_scf_384(sci, sci->scf + igr, scratch.grbuf[0]);
|
||||
drmp3d_synth_granule(dec->qmf_state, scratch.grbuf[0], 12, info->channels, (drmp3d_sample_t*)pcm, scratch.syn[0]);
|
||||
memset(scratch.grbuf[0], 0, 576*2*sizeof(float));
|
||||
DRMP3_ZERO_MEMORY(scratch.grbuf[0], 576*2*sizeof(float));
|
||||
pcm = DRMP3_OFFSET_PTR(pcm, sizeof(drmp3d_sample_t)*384*info->channels);
|
||||
}
|
||||
if (bs_frame->pos > bs_frame->limit)
|
||||
|
@ -2396,28 +2431,6 @@ DRMP3_API void drmp3dec_f32_to_s16(const float *in, drmp3_int16 *out, size_t num
|
|||
#endif
|
||||
|
||||
|
||||
/* Standard library stuff. */
|
||||
#ifndef DRMP3_ASSERT
|
||||
#include <assert.h>
|
||||
#define DRMP3_ASSERT(expression) assert(expression)
|
||||
#endif
|
||||
#ifndef DRMP3_COPY_MEMORY
|
||||
#define DRMP3_COPY_MEMORY(dst, src, sz) memcpy((dst), (src), (sz))
|
||||
#endif
|
||||
#ifndef DRMP3_ZERO_MEMORY
|
||||
#define DRMP3_ZERO_MEMORY(p, sz) memset((p), 0, (sz))
|
||||
#endif
|
||||
#define DRMP3_ZERO_OBJECT(p) DRMP3_ZERO_MEMORY((p), sizeof(*(p)))
|
||||
#ifndef DRMP3_MALLOC
|
||||
#define DRMP3_MALLOC(sz) malloc((sz))
|
||||
#endif
|
||||
#ifndef DRMP3_REALLOC
|
||||
#define DRMP3_REALLOC(p, sz) realloc((p), (sz))
|
||||
#endif
|
||||
#ifndef DRMP3_FREE
|
||||
#define DRMP3_FREE(p) free((p))
|
||||
#endif
|
||||
|
||||
#define DRMP3_COUNTOF(x) (sizeof(x) / sizeof(x[0]))
|
||||
#define DRMP3_CLAMP(x, lo, hi) (DRMP3_MAX(lo, DRMP3_MIN(x, hi)))
|
||||
|
||||
|
@ -2649,7 +2662,7 @@ static drmp3_uint32 drmp3_decode_next_frame_ex__callbacks(drmp3* pMP3, drmp3d_sa
|
|||
|
||||
/* First we need to move the data down. */
|
||||
if (pMP3->pData != NULL) {
|
||||
memmove(pMP3->pData, pMP3->pData + pMP3->dataConsumed, pMP3->dataSize);
|
||||
DRMP3_MOVE_MEMORY(pMP3->pData, pMP3->pData + pMP3->dataConsumed, pMP3->dataSize);
|
||||
}
|
||||
|
||||
pMP3->dataConsumed = 0;
|
||||
|
@ -2709,7 +2722,7 @@ static drmp3_uint32 drmp3_decode_next_frame_ex__callbacks(drmp3* pMP3, drmp3d_sa
|
|||
size_t bytesRead;
|
||||
|
||||
/* First we need to move the data down. */
|
||||
memmove(pMP3->pData, pMP3->pData + pMP3->dataConsumed, pMP3->dataSize);
|
||||
DRMP3_MOVE_MEMORY(pMP3->pData, pMP3->pData + pMP3->dataConsumed, pMP3->dataSize);
|
||||
pMP3->dataConsumed = 0;
|
||||
|
||||
if (pMP3->dataCapacity == pMP3->dataSize) {
|
||||
|
@ -2754,12 +2767,22 @@ static drmp3_uint32 drmp3_decode_next_frame_ex__memory(drmp3* pMP3, drmp3d_sampl
|
|||
return 0;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
pcmFramesRead = drmp3dec_decode_frame(&pMP3->decoder, pMP3->memory.pData + pMP3->memory.currentReadPos, (int)(pMP3->memory.dataSize - pMP3->memory.currentReadPos), pPCMFrames, &info);
|
||||
if (pcmFramesRead > 0) {
|
||||
pcmFramesRead = drmp3_hdr_frame_samples(pMP3->decoder.header);
|
||||
pMP3->pcmFramesConsumedInMP3Frame = 0;
|
||||
pMP3->pcmFramesRemainingInMP3Frame = pcmFramesRead;
|
||||
pMP3->mp3FrameChannels = info.channels;
|
||||
pMP3->mp3FrameSampleRate = info.hz;
|
||||
break;
|
||||
} else if (info.frame_bytes > 0) {
|
||||
/* No frames were read, but it looks like we skipped past one. Read the next MP3 frame. */
|
||||
pMP3->memory.currentReadPos += (size_t)info.frame_bytes;
|
||||
} else {
|
||||
/* Nothing at all was read. Abort. */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Consume the data. */
|
||||
|
@ -2822,7 +2845,7 @@ static drmp3_bool32 drmp3_init_internal(drmp3* pMP3, drmp3_read_proc onRead, drm
|
|||
}
|
||||
|
||||
/* Decode the first frame to confirm that it is indeed a valid MP3 stream. */
|
||||
if (!drmp3_decode_next_frame(pMP3)) {
|
||||
if (drmp3_decode_next_frame(pMP3) == 0) {
|
||||
drmp3__free_from_callbacks(pMP3->pData, &pMP3->allocationCallbacks); /* The call above may have allocated memory. Need to make sure it's freed before aborting. */
|
||||
return DRMP3_FALSE; /* Not a valid MP3 stream. */
|
||||
}
|
||||
|
@ -4177,7 +4200,7 @@ static float* drmp3__full_read_and_close_f32(drmp3* pMP3, drmp3_config* pConfig,
|
|||
|
||||
oldFramesBufferSize = framesCapacity * pMP3->channels * sizeof(float);
|
||||
newFramesBufferSize = newFramesCap * pMP3->channels * sizeof(float);
|
||||
if (newFramesBufferSize > DRMP3_SIZE_MAX) {
|
||||
if (newFramesBufferSize > (drmp3_uint64)DRMP3_SIZE_MAX) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -4244,7 +4267,7 @@ static drmp3_int16* drmp3__full_read_and_close_s16(drmp3* pMP3, drmp3_config* pC
|
|||
|
||||
oldFramesBufferSize = framesCapacity * pMP3->channels * sizeof(drmp3_int16);
|
||||
newFramesBufferSize = newFramesCap * pMP3->channels * sizeof(drmp3_int16);
|
||||
if (newFramesBufferSize > DRMP3_SIZE_MAX) {
|
||||
if (newFramesBufferSize > (drmp3_uint64)DRMP3_SIZE_MAX) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -4450,6 +4473,20 @@ counts rather than sample counts.
|
|||
/*
|
||||
REVISION HISTORY
|
||||
================
|
||||
v0.6.31 - 2021-08-22
|
||||
- Fix a bug when loading from memory.
|
||||
|
||||
v0.6.30 - 2021-08-16
|
||||
- Silence some warnings.
|
||||
- Replace memory operations with DRMP3_* macros.
|
||||
|
||||
v0.6.29 - 2021-08-08
|
||||
- Bring up to date with minimp3.
|
||||
|
||||
v0.6.28 - 2021-07-31
|
||||
- Fix platform detection for ARM64.
|
||||
- Fix a compilation error with C89.
|
||||
|
||||
v0.6.27 - 2021-02-21
|
||||
- Fix a warning due to referencing _MSC_VER when it is undefined.
|
||||
|
||||
|
|
2366
raylib/external/dr_wav.h
vendored
2366
raylib/external/dr_wav.h
vendored
File diff suppressed because it is too large
Load diff
13688
raylib/external/glad.h
vendored
13688
raylib/external/glad.h
vendored
File diff suppressed because it is too large
Load diff
45
raylib/external/glfw/include/GLFW/glfw3.h
vendored
45
raylib/external/glfw/include/GLFW/glfw3.h
vendored
|
@ -276,23 +276,24 @@ extern "C" {
|
|||
|
||||
/*! @name GLFW version macros
|
||||
* @{ */
|
||||
/*! @brief The major version number of the GLFW library.
|
||||
/*! @brief The major version number of the GLFW header.
|
||||
*
|
||||
* This is incremented when the API is changed in non-compatible ways.
|
||||
* The major version number of the GLFW header. This is incremented when the
|
||||
* API is changed in non-compatible ways.
|
||||
* @ingroup init
|
||||
*/
|
||||
#define GLFW_VERSION_MAJOR 3
|
||||
/*! @brief The minor version number of the GLFW library.
|
||||
/*! @brief The minor version number of the GLFW header.
|
||||
*
|
||||
* This is incremented when features are added to the API but it remains
|
||||
* backward-compatible.
|
||||
* The minor version number of the GLFW header. This is incremented when
|
||||
* features are added to the API but it remains backward-compatible.
|
||||
* @ingroup init
|
||||
*/
|
||||
#define GLFW_VERSION_MINOR 4
|
||||
/*! @brief The revision number of the GLFW library.
|
||||
/*! @brief The revision number of the GLFW header.
|
||||
*
|
||||
* This is incremented when a bug fix release is made that does not contain any
|
||||
* API changes.
|
||||
* The revision number of the GLFW header. This is incremented when a bug fix
|
||||
* release is made that does not contain any API changes.
|
||||
* @ingroup init
|
||||
*/
|
||||
#define GLFW_VERSION_REVISION 0
|
||||
|
@ -977,9 +978,10 @@ extern "C" {
|
|||
* Monitor refresh rate [hint](@ref GLFW_REFRESH_RATE).
|
||||
*/
|
||||
#define GLFW_REFRESH_RATE 0x0002100F
|
||||
/*! @brief Framebuffer double buffering hint.
|
||||
/*! @brief Framebuffer double buffering hint and attribute.
|
||||
*
|
||||
* Framebuffer double buffering [hint](@ref GLFW_DOUBLEBUFFER).
|
||||
* Framebuffer double buffering [hint](@ref GLFW_DOUBLEBUFFER_hint) and
|
||||
* [attribute](@ref GLFW_DOUBLEBUFFER_attrib).
|
||||
*/
|
||||
#define GLFW_DOUBLEBUFFER 0x00021010
|
||||
|
||||
|
@ -1250,6 +1252,11 @@ extern "C" {
|
|||
* macOS specific [init hint](@ref GLFW_COCOA_MENUBAR_hint).
|
||||
*/
|
||||
#define GLFW_COCOA_MENUBAR 0x00051002
|
||||
/*! @brief X11 specific init hint.
|
||||
*
|
||||
* X11 specific [init hint](@ref GLFW_X11_XCB_VULKAN_SURFACE_hint).
|
||||
*/
|
||||
#define GLFW_X11_XCB_VULKAN_SURFACE 0x00052001
|
||||
/*! @} */
|
||||
|
||||
#define GLFW_DONT_CARE -1
|
||||
|
@ -2417,8 +2424,9 @@ GLFWAPI GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun callback);
|
|||
*
|
||||
* This function returns an array of all video modes supported by the specified
|
||||
* monitor. The returned array is sorted in ascending order, first by color
|
||||
* bit depth (the sum of all channel depths) and then by resolution area (the
|
||||
* product of width and height).
|
||||
* bit depth (the sum of all channel depths), then by resolution area (the
|
||||
* product of width and height), then resolution width and finally by refresh
|
||||
* rate.
|
||||
*
|
||||
* @param[in] monitor The monitor to query.
|
||||
* @param[out] count Where to store the number of video modes in the returned
|
||||
|
@ -5865,9 +5873,8 @@ GLFWAPI int glfwVulkanSupported(void);
|
|||
* returned array, as it is an error to specify an extension more than once in
|
||||
* the `VkInstanceCreateInfo` struct.
|
||||
*
|
||||
* @remark @macos This function currently supports either the
|
||||
* `VK_MVK_macos_surface` extension from MoltenVK or `VK_EXT_metal_surface`
|
||||
* extension.
|
||||
* @remark @macos GLFW currently supports both the `VK_MVK_macos_surface` and
|
||||
* the newer `VK_EXT_metal_surface` extensions.
|
||||
*
|
||||
* @pointer_lifetime The returned array is allocated and freed by GLFW. You
|
||||
* should not free it yourself. It is guaranteed to be valid only until the
|
||||
|
@ -5950,7 +5957,7 @@ GLFWAPI GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, const char* p
|
|||
* GLFW_API_UNAVAILABLE and @ref GLFW_PLATFORM_ERROR.
|
||||
*
|
||||
* @remark @macos This function currently always returns `GLFW_TRUE`, as the
|
||||
* `VK_MVK_macos_surface` extension does not provide
|
||||
* `VK_MVK_macos_surface` and `VK_EXT_metal_surface` extensions do not provide
|
||||
* a `vkGetPhysicalDevice*PresentationSupport` type function.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. For
|
||||
|
@ -6013,6 +6020,12 @@ GLFWAPI int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhys
|
|||
* @remark @macos This function creates and sets a `CAMetalLayer` instance for
|
||||
* the window content view, which is required for MoltenVK to function.
|
||||
*
|
||||
* @remark @x11 GLFW by default attempts to use the `VK_KHR_xcb_surface`
|
||||
* extension, if available. You can make it prefer the `VK_KHR_xlib_surface`
|
||||
* extension by setting the
|
||||
* [GLFW_X11_XCB_VULKAN_SURFACE](@ref GLFW_X11_XCB_VULKAN_SURFACE_hint) init
|
||||
* hint.
|
||||
*
|
||||
* @thread_safety This function may be called from any thread. For
|
||||
* synchronization details of Vulkan objects, see the Vulkan specification.
|
||||
*
|
||||
|
|
|
@ -83,8 +83,8 @@ extern "C" {
|
|||
|
||||
#if defined(GLFW_EXPOSE_NATIVE_WIN32) || defined(GLFW_EXPOSE_NATIVE_WGL)
|
||||
// This is a workaround for the fact that glfw3.h needs to export APIENTRY (for
|
||||
// example to allow applications to correctly declare a GL_ARB_debug_output
|
||||
// callback) but windows.h assumes no one will define APIENTRY before it does
|
||||
// example to allow applications to correctly declare a GL_KHR_debug callback)
|
||||
// but windows.h assumes no one will define APIENTRY before it does
|
||||
#if defined(GLFW_APIENTRY_DEFINED)
|
||||
#undef APIENTRY
|
||||
#undef GLFW_APIENTRY_DEFINED
|
||||
|
@ -96,7 +96,6 @@ extern "C" {
|
|||
typedef PVOID HANDLE;
|
||||
typedef HANDLE HWND;
|
||||
#elif defined(GLFW_EXPOSE_NATIVE_COCOA) || defined(GLFW_EXPOSE_NATIVE_NSGL)
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#if defined(__OBJC__)
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#else
|
||||
|
|
9
raylib/external/glfw/src/cocoa_init.m
vendored
9
raylib/external/glfw/src/cocoa_init.m
vendored
|
@ -251,7 +251,7 @@ static void createKeyTables(void)
|
|||
_glfw.ns.keycodes[0x6D] = GLFW_KEY_F10;
|
||||
_glfw.ns.keycodes[0x67] = GLFW_KEY_F11;
|
||||
_glfw.ns.keycodes[0x6F] = GLFW_KEY_F12;
|
||||
_glfw.ns.keycodes[0x69] = GLFW_KEY_F13;
|
||||
_glfw.ns.keycodes[0x69] = GLFW_KEY_PRINT_SCREEN;
|
||||
_glfw.ns.keycodes[0x6B] = GLFW_KEY_F14;
|
||||
_glfw.ns.keycodes[0x71] = GLFW_KEY_F15;
|
||||
_glfw.ns.keycodes[0x6A] = GLFW_KEY_F16;
|
||||
|
@ -428,9 +428,6 @@ static GLFWbool initializeTIS(void)
|
|||
{
|
||||
if (_glfw.hints.init.ns.menubar)
|
||||
{
|
||||
// In case we are unbundled, make us a proper UI application
|
||||
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||
|
||||
// Menu bar setup must go between sharedApplication and finishLaunching
|
||||
// in order to properly emulate the behavior of NSApplicationMain
|
||||
|
||||
|
@ -557,6 +554,10 @@ int _glfwPlatformInit(void)
|
|||
if (![[NSRunningApplication currentApplication] isFinishedLaunching])
|
||||
[NSApp run];
|
||||
|
||||
// In case we are unbundled, make us a proper UI application
|
||||
if (_glfw.hints.init.ns.menubar)
|
||||
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||
|
||||
return GLFW_TRUE;
|
||||
|
||||
} // autoreleasepool
|
||||
|
|
89
raylib/external/glfw/src/cocoa_monitor.m
vendored
89
raylib/external/glfw/src/cocoa_monitor.m
vendored
|
@ -39,8 +39,21 @@
|
|||
|
||||
// Get the name of the specified display, or NULL
|
||||
//
|
||||
static char* getDisplayName(CGDirectDisplayID displayID)
|
||||
static char* getMonitorName(CGDirectDisplayID displayID, NSScreen* screen)
|
||||
{
|
||||
// IOKit doesn't work on Apple Silicon anymore
|
||||
// Luckily, 10.15 introduced -[NSScreen localizedName].
|
||||
// Use it if available, and fall back to IOKit otherwise.
|
||||
if (screen)
|
||||
{
|
||||
if ([screen respondsToSelector:@selector(localizedName)])
|
||||
{
|
||||
NSString* name = [screen valueForKey:@"localizedName"];
|
||||
if (name)
|
||||
return _glfw_strdup([name UTF8String]);
|
||||
}
|
||||
}
|
||||
|
||||
io_iterator_t it;
|
||||
io_service_t service;
|
||||
CFDictionaryRef info;
|
||||
|
@ -50,7 +63,7 @@ static char* getDisplayName(CGDirectDisplayID displayID)
|
|||
&it) != 0)
|
||||
{
|
||||
// This may happen if a desktop Mac is running headless
|
||||
return NULL;
|
||||
return _glfw_strdup("Display");
|
||||
}
|
||||
|
||||
while ((service = IOIteratorNext(it)) != 0)
|
||||
|
@ -88,7 +101,7 @@ static char* getDisplayName(CGDirectDisplayID displayID)
|
|||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"Cocoa: Failed to find service port for display");
|
||||
return NULL;
|
||||
return _glfw_strdup("Display");
|
||||
}
|
||||
|
||||
CFDictionaryRef names =
|
||||
|
@ -101,7 +114,7 @@ static char* getDisplayName(CGDirectDisplayID displayID)
|
|||
{
|
||||
// This may happen if a desktop Mac is running headless
|
||||
CFRelease(info);
|
||||
return NULL;
|
||||
return _glfw_strdup("Display");
|
||||
}
|
||||
|
||||
const CFIndex size =
|
||||
|
@ -209,31 +222,6 @@ static void endFadeReservation(CGDisplayFadeReservationToken token)
|
|||
}
|
||||
}
|
||||
|
||||
// Finds and caches the NSScreen corresponding to the specified monitor
|
||||
//
|
||||
static GLFWbool refreshMonitorScreen(_GLFWmonitor* monitor)
|
||||
{
|
||||
if (monitor->ns.screen)
|
||||
return GLFW_TRUE;
|
||||
|
||||
for (NSScreen* screen in [NSScreen screens])
|
||||
{
|
||||
NSNumber* displayID = [screen deviceDescription][@"NSScreenNumber"];
|
||||
|
||||
// HACK: Compare unit numbers instead of display IDs to work around
|
||||
// display replacement on machines with automatic graphics
|
||||
// switching
|
||||
if (monitor->ns.unitNumber == CGDisplayUnitNumber([displayID unsignedIntValue]))
|
||||
{
|
||||
monitor->ns.screen = screen;
|
||||
return GLFW_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR, "Cocoa: Failed to find a screen for monitor");
|
||||
return GLFW_FALSE;
|
||||
}
|
||||
|
||||
// Returns the display refresh rate queried from the I/O registry
|
||||
//
|
||||
static double getFallbackRefreshRate(CGDirectDisplayID displayID)
|
||||
|
@ -334,27 +322,46 @@ void _glfwPollMonitorsNS(void)
|
|||
if (CGDisplayIsAsleep(displays[i]))
|
||||
continue;
|
||||
|
||||
const uint32_t unitNumber = CGDisplayUnitNumber(displays[i]);
|
||||
NSScreen* screen = nil;
|
||||
|
||||
for (screen in [NSScreen screens])
|
||||
{
|
||||
NSNumber* screenNumber = [screen deviceDescription][@"NSScreenNumber"];
|
||||
|
||||
// HACK: Compare unit numbers instead of display IDs to work around
|
||||
// display replacement on machines with automatic graphics
|
||||
// switching
|
||||
const uint32_t unitNumber = CGDisplayUnitNumber(displays[i]);
|
||||
for (uint32_t j = 0; j < disconnectedCount; j++)
|
||||
if (CGDisplayUnitNumber([screenNumber unsignedIntValue]) == unitNumber)
|
||||
break;
|
||||
}
|
||||
|
||||
// HACK: Compare unit numbers instead of display IDs to work around
|
||||
// display replacement on machines with automatic graphics
|
||||
// switching
|
||||
uint32_t j;
|
||||
for (j = 0; j < disconnectedCount; j++)
|
||||
{
|
||||
if (disconnected[j] && disconnected[j]->ns.unitNumber == unitNumber)
|
||||
{
|
||||
disconnected[j]->ns.screen = screen;
|
||||
disconnected[j] = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (j < disconnectedCount)
|
||||
continue;
|
||||
|
||||
const CGSize size = CGDisplayScreenSize(displays[i]);
|
||||
char* name = getDisplayName(displays[i]);
|
||||
char* name = getMonitorName(displays[i], screen);
|
||||
if (!name)
|
||||
name = _glfw_strdup("Unknown");
|
||||
continue;
|
||||
|
||||
_GLFWmonitor* monitor = _glfwAllocMonitor(name, size.width, size.height);
|
||||
monitor->ns.displayID = displays[i];
|
||||
monitor->ns.unitNumber = unitNumber;
|
||||
monitor->ns.screen = screen;
|
||||
|
||||
free(name);
|
||||
|
||||
|
@ -463,8 +470,11 @@ void _glfwPlatformGetMonitorContentScale(_GLFWmonitor* monitor,
|
|||
{
|
||||
@autoreleasepool {
|
||||
|
||||
if (!refreshMonitorScreen(monitor))
|
||||
return;
|
||||
if (!monitor->ns.screen)
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"Cocoa: Cannot query content scale without screen");
|
||||
}
|
||||
|
||||
const NSRect points = [monitor->ns.screen frame];
|
||||
const NSRect pixels = [monitor->ns.screen convertRectToBacking:points];
|
||||
|
@ -483,8 +493,11 @@ void _glfwPlatformGetMonitorWorkarea(_GLFWmonitor* monitor,
|
|||
{
|
||||
@autoreleasepool {
|
||||
|
||||
if (!refreshMonitorScreen(monitor))
|
||||
return;
|
||||
if (!monitor->ns.screen)
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"Cocoa: Cannot query workarea without screen");
|
||||
}
|
||||
|
||||
const NSRect frameRect = [monitor->ns.screen visibleFrame];
|
||||
|
||||
|
@ -527,7 +540,7 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count)
|
|||
}
|
||||
|
||||
// Skip duplicate modes
|
||||
if (i < *count)
|
||||
if (j < *count)
|
||||
continue;
|
||||
|
||||
(*count)++;
|
||||
|
|
42
raylib/external/glfw/src/cocoa_window.m
vendored
42
raylib/external/glfw/src/cocoa_window.m
vendored
|
@ -1635,14 +1635,21 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
|||
SEL cursorSelector = NULL;
|
||||
|
||||
// HACK: Try to use a private message
|
||||
if (shape == GLFW_RESIZE_EW_CURSOR)
|
||||
switch (shape)
|
||||
{
|
||||
case GLFW_RESIZE_EW_CURSOR:
|
||||
cursorSelector = NSSelectorFromString(@"_windowResizeEastWestCursor");
|
||||
else if (shape == GLFW_RESIZE_NS_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_NS_CURSOR:
|
||||
cursorSelector = NSSelectorFromString(@"_windowResizeNorthSouthCursor");
|
||||
else if (shape == GLFW_RESIZE_NWSE_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_NWSE_CURSOR:
|
||||
cursorSelector = NSSelectorFromString(@"_windowResizeNorthWestSouthEastCursor");
|
||||
else if (shape == GLFW_RESIZE_NESW_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_NESW_CURSOR:
|
||||
cursorSelector = NSSelectorFromString(@"_windowResizeNorthEastSouthWestCursor");
|
||||
break;
|
||||
}
|
||||
|
||||
if (cursorSelector && [NSCursor respondsToSelector:cursorSelector])
|
||||
{
|
||||
|
@ -1653,22 +1660,33 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
|||
|
||||
if (!cursor->ns.object)
|
||||
{
|
||||
if (shape == GLFW_ARROW_CURSOR)
|
||||
switch (shape)
|
||||
{
|
||||
case GLFW_ARROW_CURSOR:
|
||||
cursor->ns.object = [NSCursor arrowCursor];
|
||||
else if (shape == GLFW_IBEAM_CURSOR)
|
||||
break;
|
||||
case GLFW_IBEAM_CURSOR:
|
||||
cursor->ns.object = [NSCursor IBeamCursor];
|
||||
else if (shape == GLFW_CROSSHAIR_CURSOR)
|
||||
break;
|
||||
case GLFW_CROSSHAIR_CURSOR:
|
||||
cursor->ns.object = [NSCursor crosshairCursor];
|
||||
else if (shape == GLFW_POINTING_HAND_CURSOR)
|
||||
break;
|
||||
case GLFW_POINTING_HAND_CURSOR:
|
||||
cursor->ns.object = [NSCursor pointingHandCursor];
|
||||
else if (shape == GLFW_RESIZE_EW_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_EW_CURSOR:
|
||||
cursor->ns.object = [NSCursor resizeLeftRightCursor];
|
||||
else if (shape == GLFW_RESIZE_NS_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_NS_CURSOR:
|
||||
cursor->ns.object = [NSCursor resizeUpDownCursor];
|
||||
else if (shape == GLFW_RESIZE_ALL_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_ALL_CURSOR:
|
||||
cursor->ns.object = [NSCursor closedHandCursor];
|
||||
else if (shape == GLFW_NOT_ALLOWED_CURSOR)
|
||||
break;
|
||||
case GLFW_NOT_ALLOWED_CURSOR:
|
||||
cursor->ns.object = [NSCursor operationNotAllowedCursor];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!cursor->ns.object)
|
||||
|
|
8
raylib/external/glfw/src/context.c
vendored
8
raylib/external/glfw/src/context.c
vendored
|
@ -196,12 +196,6 @@ const _GLFWfbconfig* _glfwChooseFBConfig(const _GLFWfbconfig* desired,
|
|||
continue;
|
||||
}
|
||||
|
||||
if (desired->doublebuffer != current->doublebuffer)
|
||||
{
|
||||
// Double buffering is a hard constraint
|
||||
continue;
|
||||
}
|
||||
|
||||
// Count number of missing buffers
|
||||
{
|
||||
missing = 0;
|
||||
|
@ -570,6 +564,8 @@ GLFWbool _glfwRefreshContextAttribs(_GLFWwindow* window,
|
|||
PFNGLCLEARPROC glClear = (PFNGLCLEARPROC)
|
||||
window->context.getProcAddress("glClear");
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
if (window->doublebuffer)
|
||||
window->context.swapBuffers(window);
|
||||
}
|
||||
|
||||
|
|
5
raylib/external/glfw/src/egl_context.c
vendored
5
raylib/external/glfw/src/egl_context.c
vendored
|
@ -173,7 +173,7 @@ static GLFWbool chooseEGLConfig(const _GLFWctxconfig* ctxconfig,
|
|||
u->stencilBits = getEGLConfigAttrib(n, EGL_STENCIL_SIZE);
|
||||
|
||||
u->samples = getEGLConfigAttrib(n, EGL_SAMPLES);
|
||||
u->doublebuffer = GLFW_TRUE;
|
||||
u->doublebuffer = desired->doublebuffer;
|
||||
|
||||
u->handle = (uintptr_t) n;
|
||||
usableCount++;
|
||||
|
@ -643,6 +643,9 @@ GLFWbool _glfwCreateContextEGL(_GLFWwindow* window,
|
|||
setAttrib(EGL_GL_COLORSPACE_KHR, EGL_GL_COLORSPACE_SRGB_KHR);
|
||||
}
|
||||
|
||||
if (!fbconfig->doublebuffer)
|
||||
setAttrib(EGL_RENDER_BUFFER, EGL_SINGLE_BUFFER);
|
||||
|
||||
setAttrib(EGL_NONE, EGL_NONE);
|
||||
|
||||
native = _glfwPlatformGetEGLNativeWindow(window);
|
||||
|
|
2
raylib/external/glfw/src/egl_context.h
vendored
2
raylib/external/glfw/src/egl_context.h
vendored
|
@ -64,6 +64,8 @@
|
|||
#define EGL_OPENGL_ES_API 0x30a0
|
||||
#define EGL_OPENGL_API 0x30a2
|
||||
#define EGL_NONE 0x3038
|
||||
#define EGL_RENDER_BUFFER 0x3086
|
||||
#define EGL_SINGLE_BUFFER 0x3085
|
||||
#define EGL_EXTENSIONS 0x3055
|
||||
#define EGL_CONTEXT_CLIENT_VERSION 0x3098
|
||||
#define EGL_NATIVE_VISUAL_ID 0x302e
|
||||
|
|
5
raylib/external/glfw/src/glx_context.c
vendored
5
raylib/external/glfw/src/glx_context.c
vendored
|
@ -92,6 +92,9 @@ static GLFWbool chooseGLXFBConfig(const _GLFWfbconfig* desired,
|
|||
continue;
|
||||
}
|
||||
|
||||
if (getGLXFBConfigAttrib(n, GLX_DOUBLEBUFFER) != desired->doublebuffer)
|
||||
continue;
|
||||
|
||||
if (desired->transparent)
|
||||
{
|
||||
XVisualInfo* vi = glXGetVisualFromFBConfig(_glfw.x11.display, n);
|
||||
|
@ -119,8 +122,6 @@ static GLFWbool chooseGLXFBConfig(const _GLFWfbconfig* desired,
|
|||
|
||||
if (getGLXFBConfigAttrib(n, GLX_STEREO))
|
||||
u->stereo = GLFW_TRUE;
|
||||
if (getGLXFBConfigAttrib(n, GLX_DOUBLEBUFFER))
|
||||
u->doublebuffer = GLFW_TRUE;
|
||||
|
||||
if (_glfw.glx.ARB_multisample)
|
||||
u->samples = getGLXFBConfigAttrib(n, GLX_SAMPLES);
|
||||
|
|
8
raylib/external/glfw/src/init.c
vendored
8
raylib/external/glfw/src/init.c
vendored
|
@ -57,7 +57,10 @@ static _GLFWinitconfig _glfwInitHints =
|
|||
{
|
||||
GLFW_TRUE, // macOS menu bar
|
||||
GLFW_TRUE // macOS bundle chdir
|
||||
}
|
||||
},
|
||||
{
|
||||
GLFW_TRUE, // X11 XCB Vulkan surface
|
||||
},
|
||||
};
|
||||
|
||||
// Terminate the library
|
||||
|
@ -298,6 +301,9 @@ GLFWAPI void glfwInitHint(int hint, int value)
|
|||
case GLFW_COCOA_MENUBAR:
|
||||
_glfwInitHints.ns.menubar = value;
|
||||
return;
|
||||
case GLFW_X11_XCB_VULKAN_SURFACE:
|
||||
_glfwInitHints.x11.xcbVulkanSurface = value;
|
||||
return;
|
||||
}
|
||||
|
||||
_glfwInputError(GLFW_INVALID_ENUM,
|
||||
|
|
3
raylib/external/glfw/src/input.c
vendored
3
raylib/external/glfw/src/input.c
vendored
|
@ -446,7 +446,6 @@ _GLFWjoystick* _glfwAllocJoystick(const char* name,
|
|||
|
||||
js = _glfw.joysticks + jid;
|
||||
js->present = GLFW_TRUE;
|
||||
js->name = _glfw_strdup(name);
|
||||
js->axes = calloc(axisCount, sizeof(float));
|
||||
js->buttons = calloc(buttonCount + (size_t) hatCount * 4, 1);
|
||||
js->hats = calloc(hatCount, 1);
|
||||
|
@ -454,6 +453,7 @@ _GLFWjoystick* _glfwAllocJoystick(const char* name,
|
|||
js->buttonCount = buttonCount;
|
||||
js->hatCount = hatCount;
|
||||
|
||||
strncpy(js->name, name, sizeof(js->name) - 1);
|
||||
strncpy(js->guid, guid, sizeof(js->guid) - 1);
|
||||
js->mapping = findValidMapping(js);
|
||||
|
||||
|
@ -464,7 +464,6 @@ _GLFWjoystick* _glfwAllocJoystick(const char* name,
|
|||
//
|
||||
void _glfwFreeJoystick(_GLFWjoystick* js)
|
||||
{
|
||||
free(js->name);
|
||||
free(js->axes);
|
||||
free(js->buttons);
|
||||
free(js->hats);
|
||||
|
|
8
raylib/external/glfw/src/internal.h
vendored
8
raylib/external/glfw/src/internal.h
vendored
|
@ -248,6 +248,9 @@ struct _GLFWinitconfig
|
|||
GLFWbool menubar;
|
||||
GLFWbool chdir;
|
||||
} ns;
|
||||
struct {
|
||||
GLFWbool xcbVulkanSurface;
|
||||
} x11;
|
||||
};
|
||||
|
||||
// Window configuration
|
||||
|
@ -384,6 +387,7 @@ struct _GLFWwindow
|
|||
GLFWbool mousePassthrough;
|
||||
GLFWbool shouldClose;
|
||||
void* userPointer;
|
||||
GLFWbool doublebuffer;
|
||||
GLFWvidmode videoMode;
|
||||
_GLFWmonitor* monitor;
|
||||
_GLFWcursor* cursor;
|
||||
|
@ -432,7 +436,7 @@ struct _GLFWwindow
|
|||
//
|
||||
struct _GLFWmonitor
|
||||
{
|
||||
char* name;
|
||||
char name[128];
|
||||
void* userPointer;
|
||||
|
||||
// Physical dimensions in millimeters.
|
||||
|
@ -493,7 +497,7 @@ struct _GLFWjoystick
|
|||
int buttonCount;
|
||||
unsigned char* hats;
|
||||
int hatCount;
|
||||
char* name;
|
||||
char name[128];
|
||||
void* userPointer;
|
||||
char guid[33];
|
||||
_GLFWmapping* mapping;
|
||||
|
|
708
raylib/external/glfw/src/mappings.h
vendored
708
raylib/external/glfw/src/mappings.h
vendored
File diff suppressed because it is too large
Load diff
4
raylib/external/glfw/src/monitor.c
vendored
4
raylib/external/glfw/src/monitor.c
vendored
|
@ -170,8 +170,7 @@ _GLFWmonitor* _glfwAllocMonitor(const char* name, int widthMM, int heightMM)
|
|||
monitor->widthMM = widthMM;
|
||||
monitor->heightMM = heightMM;
|
||||
|
||||
if (name)
|
||||
monitor->name = _glfw_strdup(name);
|
||||
strncpy(monitor->name, name, sizeof(monitor->name) - 1);
|
||||
|
||||
return monitor;
|
||||
}
|
||||
|
@ -189,7 +188,6 @@ void _glfwFreeMonitor(_GLFWmonitor* monitor)
|
|||
_glfwFreeGammaArrays(&monitor->currentRamp);
|
||||
|
||||
free(monitor->modes);
|
||||
free(monitor->name);
|
||||
free(monitor);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Generated by wayland-scanner 1.18.0 */
|
||||
/* Generated by wayland-scanner 1.19.0 */
|
||||
|
||||
/*
|
||||
* Copyright © 2015 Samsung Electronics Co., Ltd
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Generated by wayland-scanner 1.18.0 */
|
||||
/* Generated by wayland-scanner 1.19.0 */
|
||||
|
||||
#ifndef IDLE_INHIBIT_UNSTABLE_V1_CLIENT_PROTOCOL_H
|
||||
#define IDLE_INHIBIT_UNSTABLE_V1_CLIENT_PROTOCOL_H
|
||||
|
@ -45,6 +45,8 @@ struct wl_surface;
|
|||
struct zwp_idle_inhibit_manager_v1;
|
||||
struct zwp_idle_inhibitor_v1;
|
||||
|
||||
#ifndef ZWP_IDLE_INHIBIT_MANAGER_V1_INTERFACE
|
||||
#define ZWP_IDLE_INHIBIT_MANAGER_V1_INTERFACE
|
||||
/**
|
||||
* @page page_iface_zwp_idle_inhibit_manager_v1 zwp_idle_inhibit_manager_v1
|
||||
* @section page_iface_zwp_idle_inhibit_manager_v1_desc Description
|
||||
|
@ -81,6 +83,9 @@ struct zwp_idle_inhibitor_v1;
|
|||
* interface version number is reset.
|
||||
*/
|
||||
extern const struct wl_interface zwp_idle_inhibit_manager_v1_interface;
|
||||
#endif
|
||||
#ifndef ZWP_IDLE_INHIBITOR_V1_INTERFACE
|
||||
#define ZWP_IDLE_INHIBITOR_V1_INTERFACE
|
||||
/**
|
||||
* @page page_iface_zwp_idle_inhibitor_v1 zwp_idle_inhibitor_v1
|
||||
* @section page_iface_zwp_idle_inhibitor_v1_desc Description
|
||||
|
@ -117,6 +122,7 @@ extern const struct wl_interface zwp_idle_inhibit_manager_v1_interface;
|
|||
* de-idles and re-idles the inhibitor will take effect.
|
||||
*/
|
||||
extern const struct wl_interface zwp_idle_inhibitor_v1_interface;
|
||||
#endif
|
||||
|
||||
#define ZWP_IDLE_INHIBIT_MANAGER_V1_DESTROY 0
|
||||
#define ZWP_IDLE_INHIBIT_MANAGER_V1_CREATE_INHIBITOR 1
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Generated by wayland-scanner 1.18.0 */
|
||||
/* Generated by wayland-scanner 1.19.0 */
|
||||
|
||||
/*
|
||||
* Copyright © 2014 Jonas Ådahl
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Generated by wayland-scanner 1.18.0 */
|
||||
/* Generated by wayland-scanner 1.19.0 */
|
||||
|
||||
#ifndef POINTER_CONSTRAINTS_UNSTABLE_V1_CLIENT_PROTOCOL_H
|
||||
#define POINTER_CONSTRAINTS_UNSTABLE_V1_CLIENT_PROTOCOL_H
|
||||
|
@ -73,6 +73,8 @@ struct zwp_confined_pointer_v1;
|
|||
struct zwp_locked_pointer_v1;
|
||||
struct zwp_pointer_constraints_v1;
|
||||
|
||||
#ifndef ZWP_POINTER_CONSTRAINTS_V1_INTERFACE
|
||||
#define ZWP_POINTER_CONSTRAINTS_V1_INTERFACE
|
||||
/**
|
||||
* @page page_iface_zwp_pointer_constraints_v1 zwp_pointer_constraints_v1
|
||||
* @section page_iface_zwp_pointer_constraints_v1_desc Description
|
||||
|
@ -111,6 +113,9 @@ struct zwp_pointer_constraints_v1;
|
|||
* 'already_constrained' error will be raised.
|
||||
*/
|
||||
extern const struct wl_interface zwp_pointer_constraints_v1_interface;
|
||||
#endif
|
||||
#ifndef ZWP_LOCKED_POINTER_V1_INTERFACE
|
||||
#define ZWP_LOCKED_POINTER_V1_INTERFACE
|
||||
/**
|
||||
* @page page_iface_zwp_locked_pointer_v1 zwp_locked_pointer_v1
|
||||
* @section page_iface_zwp_locked_pointer_v1_desc Description
|
||||
|
@ -169,6 +174,9 @@ extern const struct wl_interface zwp_pointer_constraints_v1_interface;
|
|||
* destroyed.
|
||||
*/
|
||||
extern const struct wl_interface zwp_locked_pointer_v1_interface;
|
||||
#endif
|
||||
#ifndef ZWP_CONFINED_POINTER_V1_INTERFACE
|
||||
#define ZWP_CONFINED_POINTER_V1_INTERFACE
|
||||
/**
|
||||
* @page page_iface_zwp_confined_pointer_v1 zwp_confined_pointer_v1
|
||||
* @section page_iface_zwp_confined_pointer_v1_desc Description
|
||||
|
@ -213,6 +221,7 @@ extern const struct wl_interface zwp_locked_pointer_v1_interface;
|
|||
* be destroyed.
|
||||
*/
|
||||
extern const struct wl_interface zwp_confined_pointer_v1_interface;
|
||||
#endif
|
||||
|
||||
#ifndef ZWP_POINTER_CONSTRAINTS_V1_ERROR_ENUM
|
||||
#define ZWP_POINTER_CONSTRAINTS_V1_ERROR_ENUM
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Generated by wayland-scanner 1.18.0 */
|
||||
/* Generated by wayland-scanner 1.19.0 */
|
||||
|
||||
/*
|
||||
* Copyright © 2014 Jonas Ådahl
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Generated by wayland-scanner 1.18.0 */
|
||||
/* Generated by wayland-scanner 1.19.0 */
|
||||
|
||||
#ifndef RELATIVE_POINTER_UNSTABLE_V1_CLIENT_PROTOCOL_H
|
||||
#define RELATIVE_POINTER_UNSTABLE_V1_CLIENT_PROTOCOL_H
|
||||
|
@ -73,6 +73,8 @@ struct wl_pointer;
|
|||
struct zwp_relative_pointer_manager_v1;
|
||||
struct zwp_relative_pointer_v1;
|
||||
|
||||
#ifndef ZWP_RELATIVE_POINTER_MANAGER_V1_INTERFACE
|
||||
#define ZWP_RELATIVE_POINTER_MANAGER_V1_INTERFACE
|
||||
/**
|
||||
* @page page_iface_zwp_relative_pointer_manager_v1 zwp_relative_pointer_manager_v1
|
||||
* @section page_iface_zwp_relative_pointer_manager_v1_desc Description
|
||||
|
@ -89,6 +91,9 @@ struct zwp_relative_pointer_v1;
|
|||
* given pointer.
|
||||
*/
|
||||
extern const struct wl_interface zwp_relative_pointer_manager_v1_interface;
|
||||
#endif
|
||||
#ifndef ZWP_RELATIVE_POINTER_V1_INTERFACE
|
||||
#define ZWP_RELATIVE_POINTER_V1_INTERFACE
|
||||
/**
|
||||
* @page page_iface_zwp_relative_pointer_v1 zwp_relative_pointer_v1
|
||||
* @section page_iface_zwp_relative_pointer_v1_desc Description
|
||||
|
@ -109,6 +114,7 @@ extern const struct wl_interface zwp_relative_pointer_manager_v1_interface;
|
|||
* focus.
|
||||
*/
|
||||
extern const struct wl_interface zwp_relative_pointer_v1_interface;
|
||||
#endif
|
||||
|
||||
#define ZWP_RELATIVE_POINTER_MANAGER_V1_DESTROY 0
|
||||
#define ZWP_RELATIVE_POINTER_MANAGER_V1_GET_RELATIVE_POINTER 1
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Generated by wayland-scanner 1.18.0 */
|
||||
/* Generated by wayland-scanner 1.19.0 */
|
||||
|
||||
/*
|
||||
* Copyright © 2013-2016 Collabora, Ltd.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Generated by wayland-scanner 1.18.0 */
|
||||
/* Generated by wayland-scanner 1.19.0 */
|
||||
|
||||
#ifndef VIEWPORTER_CLIENT_PROTOCOL_H
|
||||
#define VIEWPORTER_CLIENT_PROTOCOL_H
|
||||
|
@ -45,6 +45,8 @@ struct wl_surface;
|
|||
struct wp_viewport;
|
||||
struct wp_viewporter;
|
||||
|
||||
#ifndef WP_VIEWPORTER_INTERFACE
|
||||
#define WP_VIEWPORTER_INTERFACE
|
||||
/**
|
||||
* @page page_iface_wp_viewporter wp_viewporter
|
||||
* @section page_iface_wp_viewporter_desc Description
|
||||
|
@ -69,6 +71,9 @@ struct wp_viewporter;
|
|||
* surface size.
|
||||
*/
|
||||
extern const struct wl_interface wp_viewporter_interface;
|
||||
#endif
|
||||
#ifndef WP_VIEWPORT_INTERFACE
|
||||
#define WP_VIEWPORT_INTERFACE
|
||||
/**
|
||||
* @page page_iface_wp_viewport wp_viewport
|
||||
* @section page_iface_wp_viewport_desc Description
|
||||
|
@ -203,6 +208,7 @@ extern const struct wl_interface wp_viewporter_interface;
|
|||
* on the next wl_surface.commit.
|
||||
*/
|
||||
extern const struct wl_interface wp_viewport_interface;
|
||||
#endif
|
||||
|
||||
#ifndef WP_VIEWPORTER_ERROR_ENUM
|
||||
#define WP_VIEWPORTER_ERROR_ENUM
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Generated by wayland-scanner 1.18.0 */
|
||||
/* Generated by wayland-scanner 1.19.0 */
|
||||
|
||||
/*
|
||||
* Copyright © 2018 Simon Ser
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Generated by wayland-scanner 1.18.0 */
|
||||
/* Generated by wayland-scanner 1.19.0 */
|
||||
|
||||
#ifndef XDG_DECORATION_UNSTABLE_V1_CLIENT_PROTOCOL_H
|
||||
#define XDG_DECORATION_UNSTABLE_V1_CLIENT_PROTOCOL_H
|
||||
|
@ -45,6 +45,8 @@ struct xdg_toplevel;
|
|||
struct zxdg_decoration_manager_v1;
|
||||
struct zxdg_toplevel_decoration_v1;
|
||||
|
||||
#ifndef ZXDG_DECORATION_MANAGER_V1_INTERFACE
|
||||
#define ZXDG_DECORATION_MANAGER_V1_INTERFACE
|
||||
/**
|
||||
* @page page_iface_zxdg_decoration_manager_v1 zxdg_decoration_manager_v1
|
||||
* @section page_iface_zxdg_decoration_manager_v1_desc Description
|
||||
|
@ -101,6 +103,9 @@ struct zxdg_toplevel_decoration_v1;
|
|||
* interface version number is reset.
|
||||
*/
|
||||
extern const struct wl_interface zxdg_decoration_manager_v1_interface;
|
||||
#endif
|
||||
#ifndef ZXDG_TOPLEVEL_DECORATION_V1_INTERFACE
|
||||
#define ZXDG_TOPLEVEL_DECORATION_V1_INTERFACE
|
||||
/**
|
||||
* @page page_iface_zxdg_toplevel_decoration_v1 zxdg_toplevel_decoration_v1
|
||||
* @section page_iface_zxdg_toplevel_decoration_v1_desc Description
|
||||
|
@ -125,6 +130,7 @@ extern const struct wl_interface zxdg_decoration_manager_v1_interface;
|
|||
* xdg_toplevel.
|
||||
*/
|
||||
extern const struct wl_interface zxdg_toplevel_decoration_v1_interface;
|
||||
#endif
|
||||
|
||||
#define ZXDG_DECORATION_MANAGER_V1_DESTROY 0
|
||||
#define ZXDG_DECORATION_MANAGER_V1_GET_TOPLEVEL_DECORATION 1
|
||||
|
@ -332,7 +338,7 @@ zxdg_toplevel_decoration_v1_destroy(struct zxdg_toplevel_decoration_v1 *zxdg_top
|
|||
* that the client prefers the provided decoration mode.
|
||||
*
|
||||
* After requesting a decoration mode, the compositor will respond by
|
||||
* emitting a xdg_surface.configure event. The client should then update
|
||||
* emitting an xdg_surface.configure event. The client should then update
|
||||
* its content, drawing it without decorations if the received mode is
|
||||
* server-side decorations. The client must also acknowledge the configure
|
||||
* when committing the new content (see xdg_surface.ack_configure).
|
||||
|
@ -341,7 +347,7 @@ zxdg_toplevel_decoration_v1_destroy(struct zxdg_toplevel_decoration_v1 *zxdg_top
|
|||
* different mode instead.
|
||||
*
|
||||
* Clients whose decoration mode depend on the xdg_toplevel state may send
|
||||
* a set_mode request in response to a xdg_surface.configure event and wait
|
||||
* a set_mode request in response to an xdg_surface.configure event and wait
|
||||
* for the next xdg_surface.configure event to prevent unwanted state.
|
||||
* Such clients are responsible for preventing configure loops and must
|
||||
* make sure not to send multiple successive set_mode requests with the
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Generated by wayland-scanner 1.18.0 */
|
||||
/* Generated by wayland-scanner 1.19.0 */
|
||||
|
||||
/*
|
||||
* Copyright © 2008-2013 Kristian Høgsberg
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* Generated by wayland-scanner 1.18.0 */
|
||||
/* Generated by wayland-scanner 1.19.0 */
|
||||
|
||||
#ifndef XDG_SHELL_CLIENT_PROTOCOL_H
|
||||
#define XDG_SHELL_CLIENT_PROTOCOL_H
|
||||
|
@ -58,6 +58,8 @@ struct xdg_surface;
|
|||
struct xdg_toplevel;
|
||||
struct xdg_wm_base;
|
||||
|
||||
#ifndef XDG_WM_BASE_INTERFACE
|
||||
#define XDG_WM_BASE_INTERFACE
|
||||
/**
|
||||
* @page page_iface_xdg_wm_base xdg_wm_base
|
||||
* @section page_iface_xdg_wm_base_desc Description
|
||||
|
@ -80,6 +82,9 @@ struct xdg_wm_base;
|
|||
* creating transient windows such as popup menus.
|
||||
*/
|
||||
extern const struct wl_interface xdg_wm_base_interface;
|
||||
#endif
|
||||
#ifndef XDG_POSITIONER_INTERFACE
|
||||
#define XDG_POSITIONER_INTERFACE
|
||||
/**
|
||||
* @page page_iface_xdg_positioner xdg_positioner
|
||||
* @section page_iface_xdg_positioner_desc Description
|
||||
|
@ -130,6 +135,9 @@ extern const struct wl_interface xdg_wm_base_interface;
|
|||
* positioning a surface raises an error.
|
||||
*/
|
||||
extern const struct wl_interface xdg_positioner_interface;
|
||||
#endif
|
||||
#ifndef XDG_SURFACE_INTERFACE
|
||||
#define XDG_SURFACE_INTERFACE
|
||||
/**
|
||||
* @page page_iface_xdg_surface xdg_surface
|
||||
* @section page_iface_xdg_surface_desc Description
|
||||
|
@ -159,6 +167,11 @@ extern const struct wl_interface xdg_positioner_interface;
|
|||
* manipulate a buffer prior to the first xdg_surface.configure call must
|
||||
* also be treated as errors.
|
||||
*
|
||||
* After creating a role-specific object and setting it up, the client must
|
||||
* perform an initial commit without any buffer attached. The compositor
|
||||
* will reply with an xdg_surface.configure event. The client must
|
||||
* acknowledge it and is then allowed to attach a buffer to map the surface.
|
||||
*
|
||||
* Mapping an xdg_surface-based role surface is defined as making it
|
||||
* possible for the surface to be shown by the compositor. Note that
|
||||
* a mapped surface is not guaranteed to be visible once it is mapped.
|
||||
|
@ -204,6 +217,11 @@ extern const struct wl_interface xdg_positioner_interface;
|
|||
* manipulate a buffer prior to the first xdg_surface.configure call must
|
||||
* also be treated as errors.
|
||||
*
|
||||
* After creating a role-specific object and setting it up, the client must
|
||||
* perform an initial commit without any buffer attached. The compositor
|
||||
* will reply with an xdg_surface.configure event. The client must
|
||||
* acknowledge it and is then allowed to attach a buffer to map the surface.
|
||||
*
|
||||
* Mapping an xdg_surface-based role surface is defined as making it
|
||||
* possible for the surface to be shown by the compositor. Note that
|
||||
* a mapped surface is not guaranteed to be visible once it is mapped.
|
||||
|
@ -220,6 +238,9 @@ extern const struct wl_interface xdg_positioner_interface;
|
|||
* has not been destroyed.
|
||||
*/
|
||||
extern const struct wl_interface xdg_surface_interface;
|
||||
#endif
|
||||
#ifndef XDG_TOPLEVEL_INTERFACE
|
||||
#define XDG_TOPLEVEL_INTERFACE
|
||||
/**
|
||||
* @page page_iface_xdg_toplevel xdg_toplevel
|
||||
* @section page_iface_xdg_toplevel_desc Description
|
||||
|
@ -234,7 +255,11 @@ extern const struct wl_interface xdg_surface_interface;
|
|||
* by the compositor until it is explicitly mapped again.
|
||||
* All active operations (e.g., move, resize) are canceled and all
|
||||
* attributes (e.g. title, state, stacking, ...) are discarded for
|
||||
* an xdg_toplevel surface when it is unmapped.
|
||||
* an xdg_toplevel surface when it is unmapped. The xdg_toplevel returns to
|
||||
* the state it had right after xdg_surface.get_toplevel. The client
|
||||
* can re-map the toplevel by perfoming a commit without any buffer
|
||||
* attached, waiting for a configure event and handling it as usual (see
|
||||
* xdg_surface description).
|
||||
*
|
||||
* Attaching a null buffer to a toplevel unmaps the surface.
|
||||
* @section page_iface_xdg_toplevel_api API
|
||||
|
@ -253,11 +278,18 @@ extern const struct wl_interface xdg_surface_interface;
|
|||
* by the compositor until it is explicitly mapped again.
|
||||
* All active operations (e.g., move, resize) are canceled and all
|
||||
* attributes (e.g. title, state, stacking, ...) are discarded for
|
||||
* an xdg_toplevel surface when it is unmapped.
|
||||
* an xdg_toplevel surface when it is unmapped. The xdg_toplevel returns to
|
||||
* the state it had right after xdg_surface.get_toplevel. The client
|
||||
* can re-map the toplevel by perfoming a commit without any buffer
|
||||
* attached, waiting for a configure event and handling it as usual (see
|
||||
* xdg_surface description).
|
||||
*
|
||||
* Attaching a null buffer to a toplevel unmaps the surface.
|
||||
*/
|
||||
extern const struct wl_interface xdg_toplevel_interface;
|
||||
#endif
|
||||
#ifndef XDG_POPUP_INTERFACE
|
||||
#define XDG_POPUP_INTERFACE
|
||||
/**
|
||||
* @page page_iface_xdg_popup xdg_popup
|
||||
* @section page_iface_xdg_popup_desc Description
|
||||
|
@ -318,6 +350,7 @@ extern const struct wl_interface xdg_toplevel_interface;
|
|||
* for the xdg_popup state to take effect.
|
||||
*/
|
||||
extern const struct wl_interface xdg_popup_interface;
|
||||
#endif
|
||||
|
||||
#ifndef XDG_WM_BASE_ERROR_ENUM
|
||||
#define XDG_WM_BASE_ERROR_ENUM
|
||||
|
@ -475,7 +508,9 @@ xdg_wm_base_create_positioner(struct xdg_wm_base *xdg_wm_base)
|
|||
*
|
||||
* This creates an xdg_surface for the given surface. While xdg_surface
|
||||
* itself is not a role, the corresponding surface may only be assigned
|
||||
* a role extending xdg_surface, such as xdg_toplevel or xdg_popup.
|
||||
* a role extending xdg_surface, such as xdg_toplevel or xdg_popup. It is
|
||||
* illegal to create an xdg_surface for a wl_surface which already has an
|
||||
* assigned role and this will result in a protocol error.
|
||||
*
|
||||
* This creates an xdg_surface for the given surface. An xdg_surface is
|
||||
* used as basis to define a role to a given surface, such as xdg_toplevel
|
||||
|
@ -810,7 +845,7 @@ xdg_positioner_set_parent_size(struct xdg_positioner *xdg_positioner, int32_t pa
|
|||
/**
|
||||
* @ingroup iface_xdg_positioner
|
||||
*
|
||||
* Set the serial of a xdg_surface.configure event this positioner will be
|
||||
* Set the serial of an xdg_surface.configure event this positioner will be
|
||||
* used in response to. The compositor may use this information together
|
||||
* with set_parent_size to determine what future state the popup should be
|
||||
* constrained using.
|
||||
|
@ -1949,12 +1984,12 @@ xdg_popup_grab(struct xdg_popup *xdg_popup, struct wl_seat *seat, uint32_t seria
|
|||
*
|
||||
* If the popup is repositioned in response to a configure event for its
|
||||
* parent, the client should send an xdg_positioner.set_parent_configure
|
||||
* and possibly a xdg_positioner.set_parent_size request to allow the
|
||||
* and possibly an xdg_positioner.set_parent_size request to allow the
|
||||
* compositor to properly constrain the popup.
|
||||
*
|
||||
* If the popup is repositioned together with a parent that is being
|
||||
* resized, but not in response to a configure event, the client should
|
||||
* send a xdg_positioner.set_parent_size request.
|
||||
* send an xdg_positioner.set_parent_size request.
|
||||
*/
|
||||
static inline void
|
||||
xdg_popup_reposition(struct xdg_popup *xdg_popup, struct xdg_positioner *positioner, uint32_t token)
|
||||
|
|
10
raylib/external/glfw/src/wgl_context.c
vendored
10
raylib/external/glfw/src/wgl_context.c
vendored
|
@ -165,6 +165,9 @@ static int choosePixelFormat(_GLFWwindow* window,
|
|||
if (findAttribValue(WGL_ACCELERATION_ARB) == WGL_NO_ACCELERATION_ARB)
|
||||
continue;
|
||||
|
||||
if (findAttribValue(WGL_DOUBLE_BUFFER_ARB) != fbconfig->doublebuffer)
|
||||
continue;
|
||||
|
||||
u->redBits = findAttribValue(WGL_RED_BITS_ARB);
|
||||
u->greenBits = findAttribValue(WGL_GREEN_BITS_ARB);
|
||||
u->blueBits = findAttribValue(WGL_BLUE_BITS_ARB);
|
||||
|
@ -182,8 +185,6 @@ static int choosePixelFormat(_GLFWwindow* window,
|
|||
|
||||
if (findAttribValue(WGL_STEREO_ARB))
|
||||
u->stereo = GLFW_TRUE;
|
||||
if (findAttribValue(WGL_DOUBLE_BUFFER_ARB))
|
||||
u->doublebuffer = GLFW_TRUE;
|
||||
|
||||
if (_glfw.wgl.ARB_multisample)
|
||||
u->samples = findAttribValue(WGL_SAMPLES_ARB);
|
||||
|
@ -239,6 +240,9 @@ static int choosePixelFormat(_GLFWwindow* window,
|
|||
if (pfd.iPixelType != PFD_TYPE_RGBA)
|
||||
continue;
|
||||
|
||||
if (!!(pfd.dwFlags & PFD_DOUBLEBUFFER) != fbconfig->doublebuffer)
|
||||
continue;
|
||||
|
||||
u->redBits = pfd.cRedBits;
|
||||
u->greenBits = pfd.cGreenBits;
|
||||
u->blueBits = pfd.cBlueBits;
|
||||
|
@ -256,8 +260,6 @@ static int choosePixelFormat(_GLFWwindow* window,
|
|||
|
||||
if (pfd.dwFlags & PFD_STEREO)
|
||||
u->stereo = GLFW_TRUE;
|
||||
if (pfd.dwFlags & PFD_DOUBLEBUFFER)
|
||||
u->doublebuffer = GLFW_TRUE;
|
||||
}
|
||||
|
||||
u->handle = pixelFormat;
|
||||
|
|
8
raylib/external/glfw/src/win32_init.c
vendored
8
raylib/external/glfw/src/win32_init.c
vendored
|
@ -39,6 +39,10 @@ static const GUID _glfw_GUID_DEVINTERFACE_HID =
|
|||
|
||||
#if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG)
|
||||
|
||||
#if defined(_GLFW_BUILD_DLL)
|
||||
#warning "These symbols must be exported by the executable and have no effect in a DLL"
|
||||
#endif
|
||||
|
||||
// Executables (but not DLLs) exporting this symbol with this value will be
|
||||
// automatically directed to the high-performance GPU on Nvidia Optimus systems
|
||||
// with up-to-date drivers
|
||||
|
@ -614,7 +618,9 @@ void _glfwPlatformTerminate(void)
|
|||
const char* _glfwPlatformGetVersionString(void)
|
||||
{
|
||||
return _GLFW_VERSION_NUMBER " Win32 WGL EGL OSMesa"
|
||||
#if defined(__MINGW32__)
|
||||
#if defined(__MINGW64_VERSION_MAJOR)
|
||||
" MinGW-w64"
|
||||
#elif defined(__MINGW32__)
|
||||
" MinGW"
|
||||
#elif defined(_MSC_VER)
|
||||
" VisualC"
|
||||
|
|
7
raylib/external/glfw/src/win32_platform.h
vendored
7
raylib/external/glfw/src/win32_platform.h
vendored
|
@ -39,8 +39,8 @@
|
|||
#endif
|
||||
|
||||
// This is a workaround for the fact that glfw3.h needs to export APIENTRY (for
|
||||
// example to allow applications to correctly declare a GL_ARB_debug_output
|
||||
// callback) but windows.h assumes no one will define APIENTRY before it does
|
||||
// example to allow applications to correctly declare a GL_KHR_debug callback)
|
||||
// but windows.h assumes no one will define APIENTRY before it does
|
||||
#undef APIENTRY
|
||||
|
||||
// GLFW on Windows is Unicode only and does not work in MBCS mode
|
||||
|
@ -314,6 +314,9 @@ typedef struct _GLFWwindowWin32
|
|||
GLFWbool scaleToMonitor;
|
||||
GLFWbool keymenu;
|
||||
|
||||
// Cached size used to filter out duplicate events
|
||||
int width, height;
|
||||
|
||||
// The last received cursor position, regardless of source
|
||||
int lastCursorPosX, lastCursorPosY;
|
||||
// The last recevied high surrogate when decoding pairs of UTF-16 messages
|
||||
|
|
87
raylib/external/glfw/src/win32_window.c
vendored
87
raylib/external/glfw/src/win32_window.c
vendored
|
@ -501,7 +501,17 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||
case WM_NCCREATE:
|
||||
{
|
||||
if (_glfwIsWindows10AnniversaryUpdateOrGreaterWin32())
|
||||
{
|
||||
const CREATESTRUCTW* cs = (const CREATESTRUCTW*) lParam;
|
||||
const _GLFWwndconfig* wndconfig = cs->lpCreateParams;
|
||||
|
||||
// On per-monitor DPI aware V1 systems, only enable
|
||||
// non-client scaling for windows that scale the client area
|
||||
// We need WM_GETDPISCALEDSIZE from V2 to keep the client
|
||||
// area static when the non-client area is scaled
|
||||
if (wndconfig && wndconfig->scaleToMonitor)
|
||||
EnableNonClientDpiScaling(hWnd);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -961,6 +971,8 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||
|
||||
case WM_SIZE:
|
||||
{
|
||||
const int width = LOWORD(lParam);
|
||||
const int height = HIWORD(lParam);
|
||||
const GLFWbool iconified = wParam == SIZE_MINIMIZED;
|
||||
const GLFWbool maximized = wParam == SIZE_MAXIMIZED ||
|
||||
(window->win32.maximized &&
|
||||
|
@ -975,8 +987,14 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||
if (window->win32.maximized != maximized)
|
||||
_glfwInputWindowMaximize(window, maximized);
|
||||
|
||||
_glfwInputFramebufferSize(window, LOWORD(lParam), HIWORD(lParam));
|
||||
_glfwInputWindowSize(window, LOWORD(lParam), HIWORD(lParam));
|
||||
if (width != window->win32.width || height != window->win32.height)
|
||||
{
|
||||
window->win32.width = width;
|
||||
window->win32.height = height;
|
||||
|
||||
_glfwInputFramebufferSize(window, width, height);
|
||||
_glfwInputWindowSize(window, width, height);
|
||||
}
|
||||
|
||||
if (window->monitor && window->win32.iconified != iconified)
|
||||
{
|
||||
|
@ -1130,9 +1148,11 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
|||
const float xscale = HIWORD(wParam) / (float) USER_DEFAULT_SCREEN_DPI;
|
||||
const float yscale = LOWORD(wParam) / (float) USER_DEFAULT_SCREEN_DPI;
|
||||
|
||||
// Only apply the suggested size if the OS is new enough to have
|
||||
// sent a WM_GETDPISCALEDSIZE before this
|
||||
if (_glfwIsWindows10CreatorsUpdateOrGreaterWin32())
|
||||
// Resize windowed mode windows that either permit rescaling or that
|
||||
// need it to compensate for non-client area scaling
|
||||
if (!window->monitor &&
|
||||
(window->win32.scaleToMonitor ||
|
||||
_glfwIsWindows10CreatorsUpdateOrGreaterWin32()))
|
||||
{
|
||||
RECT* suggested = (RECT*) lParam;
|
||||
SetWindowPos(window->win32.handle, HWND_TOP,
|
||||
|
@ -1247,7 +1267,7 @@ static int createNativeWindow(_GLFWwindow* window,
|
|||
NULL, // No parent window
|
||||
NULL, // No window menu
|
||||
GetModuleHandleW(NULL),
|
||||
NULL);
|
||||
(LPVOID) wndconfig);
|
||||
|
||||
free(wideTitle);
|
||||
|
||||
|
@ -1315,6 +1335,8 @@ static int createNativeWindow(_GLFWwindow* window,
|
|||
window->win32.transparent = GLFW_TRUE;
|
||||
}
|
||||
|
||||
_glfwPlatformGetWindowSize(window, &window->win32.width, &window->win32.height);
|
||||
|
||||
return GLFW_TRUE;
|
||||
}
|
||||
|
||||
|
@ -2113,28 +2135,39 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
|||
{
|
||||
int id = 0;
|
||||
|
||||
if (shape == GLFW_ARROW_CURSOR)
|
||||
id = OCR_NORMAL;
|
||||
else if (shape == GLFW_IBEAM_CURSOR)
|
||||
id = OCR_IBEAM;
|
||||
else if (shape == GLFW_CROSSHAIR_CURSOR)
|
||||
id = OCR_CROSS;
|
||||
else if (shape == GLFW_POINTING_HAND_CURSOR)
|
||||
id = OCR_HAND;
|
||||
else if (shape == GLFW_RESIZE_EW_CURSOR)
|
||||
id = OCR_SIZEWE;
|
||||
else if (shape == GLFW_RESIZE_NS_CURSOR)
|
||||
id = OCR_SIZENS;
|
||||
else if (shape == GLFW_RESIZE_NWSE_CURSOR)
|
||||
id = OCR_SIZENWSE;
|
||||
else if (shape == GLFW_RESIZE_NESW_CURSOR)
|
||||
id = OCR_SIZENESW;
|
||||
else if (shape == GLFW_RESIZE_ALL_CURSOR)
|
||||
id = OCR_SIZEALL;
|
||||
else if (shape == GLFW_NOT_ALLOWED_CURSOR)
|
||||
id = OCR_NO;
|
||||
else
|
||||
switch (shape)
|
||||
{
|
||||
case GLFW_ARROW_CURSOR:
|
||||
id = OCR_NORMAL;
|
||||
break;
|
||||
case GLFW_IBEAM_CURSOR:
|
||||
id = OCR_IBEAM;
|
||||
break;
|
||||
case GLFW_CROSSHAIR_CURSOR:
|
||||
id = OCR_CROSS;
|
||||
break;
|
||||
case GLFW_POINTING_HAND_CURSOR:
|
||||
id = OCR_HAND;
|
||||
break;
|
||||
case GLFW_RESIZE_EW_CURSOR:
|
||||
id = OCR_SIZEWE;
|
||||
break;
|
||||
case GLFW_RESIZE_NS_CURSOR:
|
||||
id = OCR_SIZENS;
|
||||
break;
|
||||
case GLFW_RESIZE_NWSE_CURSOR:
|
||||
id = OCR_SIZENWSE;
|
||||
break;
|
||||
case GLFW_RESIZE_NESW_CURSOR:
|
||||
id = OCR_SIZENESW;
|
||||
break;
|
||||
case GLFW_RESIZE_ALL_CURSOR:
|
||||
id = OCR_SIZEALL;
|
||||
break;
|
||||
case GLFW_NOT_ALLOWED_CURSOR:
|
||||
id = OCR_NO;
|
||||
break;
|
||||
default:
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Unknown standard cursor");
|
||||
return GLFW_FALSE;
|
||||
}
|
||||
|
|
16
raylib/external/glfw/src/window.c
vendored
16
raylib/external/glfw/src/window.c
vendored
|
@ -206,6 +206,8 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height,
|
|||
window->mousePassthrough = wndconfig.mousePassthrough;
|
||||
window->cursorMode = GLFW_CURSOR_NORMAL;
|
||||
|
||||
window->doublebuffer = fbconfig.doublebuffer;
|
||||
|
||||
window->minwidth = GLFW_DONT_CARE;
|
||||
window->minheight = GLFW_DONT_CARE;
|
||||
window->maxwidth = GLFW_DONT_CARE;
|
||||
|
@ -841,6 +843,8 @@ GLFWAPI int glfwGetWindowAttrib(GLFWwindow* handle, int attrib)
|
|||
return window->floating;
|
||||
case GLFW_AUTO_ICONIFY:
|
||||
return window->autoIconify;
|
||||
case GLFW_DOUBLEBUFFER:
|
||||
return window->doublebuffer;
|
||||
case GLFW_CLIENT_API:
|
||||
return window->context.client;
|
||||
case GLFW_CONTEXT_CREATION_API:
|
||||
|
@ -882,27 +886,18 @@ GLFWAPI void glfwSetWindowAttrib(GLFWwindow* handle, int attrib, int value)
|
|||
window->autoIconify = value;
|
||||
else if (attrib == GLFW_RESIZABLE)
|
||||
{
|
||||
if (window->resizable == value)
|
||||
return;
|
||||
|
||||
window->resizable = value;
|
||||
if (!window->monitor)
|
||||
_glfwPlatformSetWindowResizable(window, value);
|
||||
}
|
||||
else if (attrib == GLFW_DECORATED)
|
||||
{
|
||||
if (window->decorated == value)
|
||||
return;
|
||||
|
||||
window->decorated = value;
|
||||
if (!window->monitor)
|
||||
_glfwPlatformSetWindowDecorated(window, value);
|
||||
}
|
||||
else if (attrib == GLFW_FLOATING)
|
||||
{
|
||||
if (window->floating == value)
|
||||
return;
|
||||
|
||||
window->floating = value;
|
||||
if (!window->monitor)
|
||||
_glfwPlatformSetWindowFloating(window, value);
|
||||
|
@ -911,9 +906,6 @@ GLFWAPI void glfwSetWindowAttrib(GLFWwindow* handle, int attrib, int value)
|
|||
window->focusOnShow = value;
|
||||
else if (attrib == GLFW_MOUSE_PASSTHROUGH)
|
||||
{
|
||||
if (window->mousePassthrough == value)
|
||||
return;
|
||||
|
||||
window->mousePassthrough = value;
|
||||
_glfwPlatformSetWindowMousePassthrough(window, value);
|
||||
}
|
||||
|
|
13
raylib/external/glfw/src/wl_init.c
vendored
13
raylib/external/glfw/src/wl_init.c
vendored
|
@ -1038,8 +1038,6 @@ int _glfwPlatformInit(void)
|
|||
char *cursorSizeEnd;
|
||||
long cursorSizeLong;
|
||||
int cursorSize;
|
||||
int i;
|
||||
_GLFWmonitor* monitor;
|
||||
|
||||
_glfw.wl.cursor.handle = _glfw_dlopen("libwayland-cursor.so.0");
|
||||
if (!_glfw.wl.cursor.handle)
|
||||
|
@ -1148,17 +1146,6 @@ int _glfwPlatformInit(void)
|
|||
// Sync so we got all initial output events
|
||||
wl_display_roundtrip(_glfw.wl.display);
|
||||
|
||||
for (i = 0; i < _glfw.monitorCount; ++i)
|
||||
{
|
||||
monitor = _glfw.monitors[i];
|
||||
if (monitor->widthMM <= 0 || monitor->heightMM <= 0)
|
||||
{
|
||||
// If Wayland does not provide a physical size, assume the default 96 DPI
|
||||
monitor->widthMM = (int) (monitor->modes[monitor->wl.currentMode].width * 25.4f / 96.f);
|
||||
monitor->heightMM = (int) (monitor->modes[monitor->wl.currentMode].height * 25.4f / 96.f);
|
||||
}
|
||||
}
|
||||
|
||||
_glfwInitTimerPOSIX();
|
||||
|
||||
_glfw.wl.timerfd = -1;
|
||||
|
|
14
raylib/external/glfw/src/wl_monitor.c
vendored
14
raylib/external/glfw/src/wl_monitor.c
vendored
|
@ -47,15 +47,13 @@ static void outputHandleGeometry(void* data,
|
|||
int32_t transform)
|
||||
{
|
||||
struct _GLFWmonitor *monitor = data;
|
||||
char name[1024];
|
||||
|
||||
monitor->wl.x = x;
|
||||
monitor->wl.y = y;
|
||||
monitor->widthMM = physicalWidth;
|
||||
monitor->heightMM = physicalHeight;
|
||||
|
||||
snprintf(name, sizeof(name), "%s %s", make, model);
|
||||
monitor->name = _glfw_strdup(name);
|
||||
snprintf(monitor->name, sizeof(monitor->name), "%s %s", make, model);
|
||||
}
|
||||
|
||||
static void outputHandleMode(void* data,
|
||||
|
@ -88,6 +86,14 @@ static void outputHandleDone(void* data, struct wl_output* output)
|
|||
{
|
||||
struct _GLFWmonitor *monitor = data;
|
||||
|
||||
if (monitor->widthMM <= 0 || monitor->heightMM <= 0)
|
||||
{
|
||||
// If Wayland does not provide a physical size, assume the default 96 DPI
|
||||
const GLFWvidmode* mode = &monitor->modes[monitor->wl.currentMode];
|
||||
monitor->widthMM = (int) (mode->width * 25.4f / 96.f);
|
||||
monitor->heightMM = (int) (mode->height * 25.4f / 96.f);
|
||||
}
|
||||
|
||||
_glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_LAST);
|
||||
}
|
||||
|
||||
|
@ -125,7 +131,7 @@ void _glfwAddOutputWayland(uint32_t name, uint32_t version)
|
|||
}
|
||||
|
||||
// The actual name of this output will be set in the geometry handler.
|
||||
monitor = _glfwAllocMonitor(NULL, 0, 0);
|
||||
monitor = _glfwAllocMonitor("", 0, 0);
|
||||
|
||||
output = wl_registry_bind(_glfw.wl.registry,
|
||||
name,
|
||||
|
|
68
raylib/external/glfw/src/wl_window.c
vendored
68
raylib/external/glfw/src/wl_window.c
vendored
|
@ -246,10 +246,10 @@ static void createDecorations(_GLFWwindow* window)
|
|||
|
||||
static void destroyDecoration(_GLFWdecorationWayland* decoration)
|
||||
{
|
||||
if (decoration->surface)
|
||||
wl_surface_destroy(decoration->surface);
|
||||
if (decoration->subsurface)
|
||||
wl_subsurface_destroy(decoration->subsurface);
|
||||
if (decoration->surface)
|
||||
wl_surface_destroy(decoration->surface);
|
||||
if (decoration->viewport)
|
||||
wp_viewport_destroy(decoration->viewport);
|
||||
decoration->surface = NULL;
|
||||
|
@ -1242,26 +1242,39 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
|||
const char* name = NULL;
|
||||
|
||||
// Try the XDG names first
|
||||
if (shape == GLFW_ARROW_CURSOR)
|
||||
switch (shape)
|
||||
{
|
||||
case GLFW_ARROW_CURSOR:
|
||||
name = "default";
|
||||
else if (shape == GLFW_IBEAM_CURSOR)
|
||||
break;
|
||||
case GLFW_IBEAM_CURSOR:
|
||||
name = "text";
|
||||
else if (shape == GLFW_CROSSHAIR_CURSOR)
|
||||
break;
|
||||
case GLFW_CROSSHAIR_CURSOR:
|
||||
name = "crosshair";
|
||||
else if (shape == GLFW_POINTING_HAND_CURSOR)
|
||||
break;
|
||||
case GLFW_POINTING_HAND_CURSOR:
|
||||
name = "pointer";
|
||||
else if (shape == GLFW_RESIZE_EW_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_EW_CURSOR:
|
||||
name = "ew-resize";
|
||||
else if (shape == GLFW_RESIZE_NS_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_NS_CURSOR:
|
||||
name = "ns-resize";
|
||||
else if (shape == GLFW_RESIZE_NWSE_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_NWSE_CURSOR:
|
||||
name = "nwse-resize";
|
||||
else if (shape == GLFW_RESIZE_NESW_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_NESW_CURSOR:
|
||||
name = "nesw-resize";
|
||||
else if (shape == GLFW_RESIZE_ALL_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_ALL_CURSOR:
|
||||
name = "all-scroll";
|
||||
else if (shape == GLFW_NOT_ALLOWED_CURSOR)
|
||||
break;
|
||||
case GLFW_NOT_ALLOWED_CURSOR:
|
||||
name = "not-allowed";
|
||||
break;
|
||||
}
|
||||
|
||||
cursor->wl.cursor = wl_cursor_theme_get_cursor(_glfw.wl.cursorTheme, name);
|
||||
|
||||
|
@ -1274,22 +1287,23 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
|||
if (!cursor->wl.cursor)
|
||||
{
|
||||
// Fall back to the core X11 names
|
||||
if (shape == GLFW_ARROW_CURSOR)
|
||||
name = "left_ptr";
|
||||
else if (shape == GLFW_IBEAM_CURSOR)
|
||||
name = "xterm";
|
||||
else if (shape == GLFW_CROSSHAIR_CURSOR)
|
||||
name = "crosshair";
|
||||
else if (shape == GLFW_POINTING_HAND_CURSOR)
|
||||
name = "hand2";
|
||||
else if (shape == GLFW_RESIZE_EW_CURSOR)
|
||||
name = "sb_h_double_arrow";
|
||||
else if (shape == GLFW_RESIZE_NS_CURSOR)
|
||||
name = "sb_v_double_arrow";
|
||||
else if (shape == GLFW_RESIZE_ALL_CURSOR)
|
||||
name = "fleur";
|
||||
else
|
||||
switch (shape)
|
||||
{
|
||||
case GLFW_ARROW_CURSOR:
|
||||
name = "left_ptr";
|
||||
case GLFW_IBEAM_CURSOR:
|
||||
name = "xterm";
|
||||
case GLFW_CROSSHAIR_CURSOR:
|
||||
name = "crosshair";
|
||||
case GLFW_POINTING_HAND_CURSOR:
|
||||
name = "hand2";
|
||||
case GLFW_RESIZE_EW_CURSOR:
|
||||
name = "sb_h_double_arrow";
|
||||
case GLFW_RESIZE_NS_CURSOR:
|
||||
name = "sb_v_double_arrow";
|
||||
case GLFW_RESIZE_ALL_CURSOR:
|
||||
name = "fleur";
|
||||
default:
|
||||
_glfwInputError(GLFW_CURSOR_UNAVAILABLE,
|
||||
"Wayland: Standard cursor shape unavailable");
|
||||
return GLFW_FALSE;
|
||||
|
|
4
raylib/external/glfw/src/x11_init.c
vendored
4
raylib/external/glfw/src/x11_init.c
vendored
|
@ -813,11 +813,15 @@ static GLFWbool initExtensions(void)
|
|||
XkbGroupStateMask, XkbGroupStateMask);
|
||||
}
|
||||
|
||||
if (_glfw.hints.init.x11.xcbVulkanSurface)
|
||||
{
|
||||
#if defined(__CYGWIN__)
|
||||
_glfw.x11.x11xcb.handle = _glfw_dlopen("libX11-xcb-1.so");
|
||||
#else
|
||||
_glfw.x11.x11xcb.handle = _glfw_dlopen("libX11-xcb.so.1");
|
||||
#endif
|
||||
}
|
||||
|
||||
if (_glfw.x11.x11xcb.handle)
|
||||
{
|
||||
_glfw.x11.x11xcb.GetXCBConnection = (PFN_XGetXCBConnection)
|
||||
|
|
75
raylib/external/glfw/src/x11_window.c
vendored
75
raylib/external/glfw/src/x11_window.c
vendored
|
@ -2485,7 +2485,11 @@ void _glfwPlatformSetWindowMonitor(_GLFWwindow* window,
|
|||
}
|
||||
|
||||
if (window->monitor)
|
||||
{
|
||||
_glfwPlatformSetWindowDecorated(window, window->decorated);
|
||||
_glfwPlatformSetWindowFloating(window, window->floating);
|
||||
releaseMonitor(window);
|
||||
}
|
||||
|
||||
_glfwInputWindowMonitor(window, monitor);
|
||||
updateNormalHints(window, width, height);
|
||||
|
@ -2935,26 +2939,39 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
|||
const int size = XcursorGetDefaultSize(_glfw.x11.display);
|
||||
const char* name = NULL;
|
||||
|
||||
if (shape == GLFW_ARROW_CURSOR)
|
||||
switch (shape)
|
||||
{
|
||||
case GLFW_ARROW_CURSOR:
|
||||
name = "default";
|
||||
else if (shape == GLFW_IBEAM_CURSOR)
|
||||
break;
|
||||
case GLFW_IBEAM_CURSOR:
|
||||
name = "text";
|
||||
else if (shape == GLFW_CROSSHAIR_CURSOR)
|
||||
break;
|
||||
case GLFW_CROSSHAIR_CURSOR:
|
||||
name = "crosshair";
|
||||
else if (shape == GLFW_POINTING_HAND_CURSOR)
|
||||
break;
|
||||
case GLFW_POINTING_HAND_CURSOR:
|
||||
name = "pointer";
|
||||
else if (shape == GLFW_RESIZE_EW_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_EW_CURSOR:
|
||||
name = "ew-resize";
|
||||
else if (shape == GLFW_RESIZE_NS_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_NS_CURSOR:
|
||||
name = "ns-resize";
|
||||
else if (shape == GLFW_RESIZE_NWSE_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_NWSE_CURSOR:
|
||||
name = "nwse-resize";
|
||||
else if (shape == GLFW_RESIZE_NESW_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_NESW_CURSOR:
|
||||
name = "nesw-resize";
|
||||
else if (shape == GLFW_RESIZE_ALL_CURSOR)
|
||||
break;
|
||||
case GLFW_RESIZE_ALL_CURSOR:
|
||||
name = "all-scroll";
|
||||
else if (shape == GLFW_NOT_ALLOWED_CURSOR)
|
||||
break;
|
||||
case GLFW_NOT_ALLOWED_CURSOR:
|
||||
name = "not-allowed";
|
||||
break;
|
||||
}
|
||||
|
||||
XcursorImage* image = XcursorLibraryLoadImage(name, theme, size);
|
||||
if (image)
|
||||
|
@ -2969,22 +2986,30 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape)
|
|||
{
|
||||
unsigned int native = 0;
|
||||
|
||||
if (shape == GLFW_ARROW_CURSOR)
|
||||
native = XC_left_ptr;
|
||||
else if (shape == GLFW_IBEAM_CURSOR)
|
||||
native = XC_xterm;
|
||||
else if (shape == GLFW_CROSSHAIR_CURSOR)
|
||||
native = XC_crosshair;
|
||||
else if (shape == GLFW_POINTING_HAND_CURSOR)
|
||||
native = XC_hand2;
|
||||
else if (shape == GLFW_RESIZE_EW_CURSOR)
|
||||
native = XC_sb_h_double_arrow;
|
||||
else if (shape == GLFW_RESIZE_NS_CURSOR)
|
||||
native = XC_sb_v_double_arrow;
|
||||
else if (shape == GLFW_RESIZE_ALL_CURSOR)
|
||||
native = XC_fleur;
|
||||
else
|
||||
switch (shape)
|
||||
{
|
||||
case GLFW_ARROW_CURSOR:
|
||||
native = XC_left_ptr;
|
||||
break;
|
||||
case GLFW_IBEAM_CURSOR:
|
||||
native = XC_xterm;
|
||||
break;
|
||||
case GLFW_CROSSHAIR_CURSOR:
|
||||
native = XC_crosshair;
|
||||
break;
|
||||
case GLFW_POINTING_HAND_CURSOR:
|
||||
native = XC_hand2;
|
||||
break;
|
||||
case GLFW_RESIZE_EW_CURSOR:
|
||||
native = XC_sb_h_double_arrow;
|
||||
break;
|
||||
case GLFW_RESIZE_NS_CURSOR:
|
||||
native = XC_sb_v_double_arrow;
|
||||
break;
|
||||
case GLFW_RESIZE_ALL_CURSOR:
|
||||
native = XC_fleur;
|
||||
break;
|
||||
default:
|
||||
_glfwInputError(GLFW_CURSOR_UNAVAILABLE,
|
||||
"X11: Standard cursor shape unavailable");
|
||||
return GLFW_FALSE;
|
||||
|
|
8840
raylib/external/miniaudio.h
vendored
8840
raylib/external/miniaudio.h
vendored
File diff suppressed because it is too large
Load diff
341
raylib/external/msf_gif.h
vendored
341
raylib/external/msf_gif.h
vendored
|
@ -13,19 +13,31 @@ USAGE EXAMPLE:
|
|||
|
||||
int width = 480, height = 320, centisecondsPerFrame = 5, bitDepth = 16;
|
||||
MsfGifState gifState = {};
|
||||
// msf_gif_bgra_flag = true; //optionally, set this flag if your pixels are in BGRA format instead of RGBA
|
||||
// msf_gif_alpha_threshold = 128; //optionally, enable transparency (see function documentation below for details)
|
||||
msf_gif_begin(&gifState, width, height);
|
||||
msf_gif_frame(&gifState, ..., centisecondsPerFrame, bitDepth, width * 4); //frame 1
|
||||
msf_gif_frame(&gifState, ..., centisecondsPerFrame, bitDepth, width * 4); //frame 2
|
||||
msf_gif_frame(&gifState, ..., centisecondsPerFrame, bitDepth, width * 4); //frame 3, etc...
|
||||
MsfGifResult result = msf_gif_end(&gifState);
|
||||
if (result.data) {
|
||||
FILE * fp = fopen("MyGif.gif", "wb");
|
||||
fwrite(result.data, result.dataSize, 1, fp);
|
||||
fclose(fp);
|
||||
}
|
||||
msf_gif_free(result);
|
||||
|
||||
Detailed function documentation can be found in the header section below.
|
||||
|
||||
|
||||
ERROR HANDLING:
|
||||
|
||||
If memory allocation fails, the functions will signal the error via their return values.
|
||||
If one function call fails, the library will free all of its allocations,
|
||||
and all subsequent calls will safely no-op and return 0 until the next call to `msf_gif_begin()`.
|
||||
Therefore, it's safe to check only the return value of `msf_gif_end()`.
|
||||
|
||||
|
||||
REPLACING MALLOC:
|
||||
|
||||
This library uses malloc+realloc+free internally for memory allocation.
|
||||
|
@ -39,10 +51,20 @@ REPLACING MALLOC:
|
|||
If your allocator needs a context pointer, you can set the `customAllocatorContext` field of the MsfGifState struct
|
||||
before calling msf_gif_begin(), and it will be passed to all subsequent allocator macro calls.
|
||||
|
||||
The maximum number of bytes the library will allocate to encode a single gif is bounded by the following formula:
|
||||
`(2 * 1024 * 1024) + (width * height * 8) + ((1024 + width * height * 1.5) * 3 * frameCount)`
|
||||
The peak heap memory usage in bytes, if using a general-purpose heap allocator, is bounded by the following formula:
|
||||
`(2 * 1024 * 1024) + (width * height * 9.5) + 1024 + (16 * frameCount) + (2 * sizeOfResultingGif)
|
||||
|
||||
|
||||
See end of file for license information.
|
||||
*/
|
||||
|
||||
//version 2.1
|
||||
//version 2.2
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// HEADER ///
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef MSF_GIF_H
|
||||
#define MSF_GIF_H
|
||||
|
@ -63,12 +85,24 @@ typedef struct { //internal use
|
|||
int depth, count, rbits, gbits, bbits;
|
||||
} MsfCookedFrame;
|
||||
|
||||
typedef struct MsfGifBuffer {
|
||||
struct MsfGifBuffer * next;
|
||||
size_t size;
|
||||
uint8_t data[1];
|
||||
} MsfGifBuffer;
|
||||
|
||||
typedef size_t (* MsfGifFileWriteFunc) (const void * buffer, size_t size, size_t count, void * stream);
|
||||
typedef struct {
|
||||
MsfGifFileWriteFunc fileWriteFunc;
|
||||
void * fileWriteData;
|
||||
MsfCookedFrame previousFrame;
|
||||
uint8_t * listHead;
|
||||
uint8_t * listTail;
|
||||
MsfCookedFrame currentFrame;
|
||||
int16_t * lzwMem;
|
||||
MsfGifBuffer * listHead;
|
||||
MsfGifBuffer * listTail;
|
||||
int width, height;
|
||||
void * customAllocatorContext;
|
||||
int framesSubmitted; //needed for transparency to work correctly (because we reach into the previous frame)
|
||||
} MsfGifState;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -83,7 +117,8 @@ extern "C" {
|
|||
int msf_gif_begin(MsfGifState * handle, int width, int height);
|
||||
|
||||
/**
|
||||
* @param pixelData Pointer to raw framebuffer data. Rows must be contiguous in memory, in RGBA8 format.
|
||||
* @param pixelData Pointer to raw framebuffer data. Rows must be contiguous in memory, in RGBA8 format
|
||||
* (or BGRA8 if you have set `msf_gif_bgra_flag = true`).
|
||||
* Note: This function does NOT free `pixelData`. You must free it yourself afterwards.
|
||||
* @param centiSecondsPerFrame How many hundredths of a second this frame should be displayed for.
|
||||
* Note: This being specified in centiseconds is a limitation of the GIF format.
|
||||
|
@ -111,6 +146,35 @@ MsfGifResult msf_gif_end(MsfGifState * handle);
|
|||
*/
|
||||
void msf_gif_free(MsfGifResult result);
|
||||
|
||||
//The gif format only supports 1-bit transparency, meaning a pixel will either be fully transparent or fully opaque.
|
||||
//Pixels with an alpha value less than the alpha threshold will be treated as transparent.
|
||||
//To enable exporting transparent gifs, set it to a value between 1 and 255 (inclusive) before calling msf_gif_frame().
|
||||
//Setting it to 0 causes the alpha channel to be ignored. Its initial value is 0.
|
||||
extern int msf_gif_alpha_threshold;
|
||||
|
||||
//Set `msf_gif_bgra_flag = true` before calling `msf_gif_frame()` if your pixels are in BGRA byte order instead of RBGA.
|
||||
extern int msf_gif_bgra_flag;
|
||||
|
||||
|
||||
|
||||
//TO-FILE FUNCTIONS
|
||||
//These functions are equivalent to the ones above, but they write results to a file incrementally,
|
||||
//instead of building a buffer in memory. This can result in lower memory usage when saving large gifs,
|
||||
//because memory usage is bounded by only the size of a single frame, and is not dependent on the number of frames.
|
||||
//There is currently no reason to use these unless you are on a memory-constrained platform.
|
||||
//If in doubt about which API to use, for now you should use the normal (non-file) functions above.
|
||||
//The signature of MsfGifFileWriteFunc matches fwrite for convenience, so that you can use the C file API like so:
|
||||
// FILE * fp = fopen("MyGif.gif", "wb");
|
||||
// msf_gif_begin_to_file(&handle, width, height, (MsfGifFileWriteFunc) fwrite, (void *) fp);
|
||||
// msf_gif_frame_to_file(...)
|
||||
// msf_gif_end_to_file(&handle);
|
||||
// fclose(fp);
|
||||
//If you use a custom file write function, you must take care to return the same values that fwrite() would return.
|
||||
//Note that all three functions will potentially write to the file.
|
||||
int msf_gif_begin_to_file(MsfGifState * handle, int width, int height, MsfGifFileWriteFunc func, void * filePointer);
|
||||
int msf_gif_frame_to_file(MsfGifState * handle, uint8_t * pixelData, int centiSecondsPerFame, int maxBitDepth, int pitchInBytes);
|
||||
int msf_gif_end_to_file(MsfGifState * handle); //returns 0 on error and non-zero on success
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif //__cplusplus
|
||||
|
@ -125,10 +189,6 @@ void msf_gif_free(MsfGifResult result);
|
|||
#ifndef MSF_GIF_ALREADY_IMPLEMENTED_IN_THIS_TRANSLATION_UNIT
|
||||
#define MSF_GIF_ALREADY_IMPLEMENTED_IN_THIS_TRANSLATION_UNIT
|
||||
|
||||
#ifndef MSF_GIF_BUFFER_INIT_SIZE
|
||||
#define MSF_GIF_BUFFER_INIT_SIZE 1024 * 1024 * 4 //4MB by default, you can increase this if you want to realloc less
|
||||
#endif
|
||||
|
||||
//ensure the library user has either defined all of malloc/realloc/free, or none
|
||||
#if defined(MSF_GIF_MALLOC) && defined(MSF_GIF_REALLOC) && defined(MSF_GIF_FREE) //ok
|
||||
#elif !defined(MSF_GIF_MALLOC) && !defined(MSF_GIF_REALLOC) && !defined(MSF_GIF_FREE) //ok
|
||||
|
@ -189,13 +249,21 @@ static inline int msf_imax(int a, int b) { return b < a? a : b; }
|
|||
#include <emmintrin.h>
|
||||
#endif
|
||||
|
||||
static MsfCookedFrame msf_cook_frame(void * allocContext, uint8_t * raw, uint8_t * used,
|
||||
int msf_gif_alpha_threshold = 0;
|
||||
int msf_gif_bgra_flag = 0;
|
||||
|
||||
static void msf_cook_frame(MsfCookedFrame * frame, uint8_t * raw, uint8_t * used,
|
||||
int width, int height, int pitch, int depth)
|
||||
{ MsfTimeFunc
|
||||
//bit depth for each channel
|
||||
const static int rdepths[17] = { 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5 };
|
||||
const static int gdepths[17] = { 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6 };
|
||||
const static int bdepths[17] = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5 };
|
||||
const static int rdepthsArray[17] = { 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5 };
|
||||
const static int gdepthsArray[17] = { 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6 };
|
||||
const static int bdepthsArray[17] = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5 };
|
||||
//this extra level of indirection looks unnecessary but we need to explicitly decay the arrays to pointers
|
||||
//in order to be able to swap them because of C's annoying not-quite-pointers, not-quite-value-types stack arrays.
|
||||
const int * rdepths = msf_gif_bgra_flag? bdepthsArray : rdepthsArray;
|
||||
const int * gdepths = gdepthsArray;
|
||||
const int * bdepths = msf_gif_bgra_flag? rdepthsArray : bdepthsArray;
|
||||
|
||||
const static int ditherKernel[16] = {
|
||||
0 << 12, 8 << 12, 2 << 12, 10 << 12,
|
||||
|
@ -204,13 +272,11 @@ static MsfCookedFrame msf_cook_frame(void * allocContext, uint8_t * raw, uint8_t
|
|||
15 << 12, 7 << 12, 13 << 12, 5 << 12,
|
||||
};
|
||||
|
||||
uint32_t * cooked = (uint32_t *) MSF_GIF_MALLOC(allocContext, width * height * sizeof(uint32_t));
|
||||
if (!cooked) { MsfCookedFrame blank = {0}; return blank; }
|
||||
|
||||
uint32_t * cooked = frame->pixels;
|
||||
int count = 0;
|
||||
MsfTimeLoop("do") do {
|
||||
int rbits = rdepths[depth], gbits = gdepths[depth], bbits = bdepths[depth];
|
||||
int paletteSize = 1 << (rbits + gbits + bbits);
|
||||
int paletteSize = (1 << (rbits + gbits + bbits)) + 1;
|
||||
memset(used, 0, paletteSize * sizeof(uint8_t));
|
||||
|
||||
//TODO: document what this math does and why it's correct
|
||||
|
@ -230,7 +296,6 @@ static MsfCookedFrame msf_cook_frame(void * allocContext, uint8_t * raw, uint8_t
|
|||
#if (defined (__SSE2__) || defined (_M_X64) || _M_IX86_FP == 2) && !defined(MSF_GIF_NO_SSE2)
|
||||
__m128i k = _mm_loadu_si128((__m128i *) &ditherKernel[(y & 3) * 4]);
|
||||
__m128i k2 = _mm_or_si128(_mm_srli_epi32(k, rbits), _mm_slli_epi32(_mm_srli_epi32(k, bbits), 16));
|
||||
// MsfTimeLoop("SIMD")
|
||||
for (; x < width - 3; x += 4) {
|
||||
uint8_t * pixels = &raw[y * pitch + x * 4];
|
||||
__m128i p = _mm_loadu_si128((__m128i *) pixels);
|
||||
|
@ -246,17 +311,30 @@ static MsfCookedFrame msf_cook_frame(void * allocContext, uint8_t * raw, uint8_t
|
|||
__m128i g2 = _mm_adds_epu16(g1, _mm_srli_epi32(k, gbits));
|
||||
__m128i g3 = _mm_and_si128(_mm_srli_epi32(g2, 16 - rbits - gbits), _mm_set1_epi32(gmask));
|
||||
|
||||
__m128i out = _mm_or_si128(_mm_or_si128(r3, g3), b3);
|
||||
|
||||
//mask in transparency based on threshold
|
||||
//NOTE: we can theoretically do a sub instead of srli by doing an unsigned compare via bias
|
||||
// to maybe save a TINY amount of throughput? but lol who cares maybe I'll do it later -m
|
||||
__m128i invAlphaMask = _mm_cmplt_epi32(_mm_srli_epi32(p, 24), _mm_set1_epi32(msf_gif_alpha_threshold));
|
||||
out = _mm_or_si128(_mm_and_si128(invAlphaMask, _mm_set1_epi32(paletteSize - 1)), _mm_andnot_si128(invAlphaMask, out));
|
||||
|
||||
//TODO: does storing this as a __m128i then reading it back as a uint32_t violate strict aliasing?
|
||||
uint32_t * c = &cooked[y * width + x];
|
||||
__m128i out = _mm_or_si128(_mm_or_si128(r3, g3), b3);
|
||||
_mm_storeu_si128((__m128i *) c, out);
|
||||
}
|
||||
#endif
|
||||
|
||||
//scalar cleanup loop
|
||||
// MsfTimeLoop("scalar")
|
||||
for (; x < width; ++x) {
|
||||
uint8_t * p = &raw[y * pitch + x * 4];
|
||||
|
||||
//transparent pixel if alpha is low
|
||||
if (p[3] < msf_gif_alpha_threshold) {
|
||||
cooked[y * width + x] = paletteSize - 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
int dx = x & 3, dy = y & 3;
|
||||
int k = ditherKernel[dy * 4 + dx];
|
||||
cooked[y * width + x] =
|
||||
|
@ -267,30 +345,25 @@ static MsfCookedFrame msf_cook_frame(void * allocContext, uint8_t * raw, uint8_t
|
|||
}
|
||||
|
||||
count = 0;
|
||||
MsfTimeLoop("mark and count") for (int i = 0; i < width * height; ++i) {
|
||||
MsfTimeLoop("mark") for (int i = 0; i < width * height; ++i) {
|
||||
used[cooked[i]] = 1;
|
||||
}
|
||||
|
||||
//count used colors
|
||||
MsfTimeLoop("count") for (int j = 0; j < paletteSize; ++j) {
|
||||
//count used colors, transparent is ignored
|
||||
MsfTimeLoop("count") for (int j = 0; j < paletteSize - 1; ++j) {
|
||||
count += used[j];
|
||||
}
|
||||
} while (count >= 256 && --depth);
|
||||
|
||||
MsfCookedFrame ret = { cooked, depth, count, rdepths[depth], gdepths[depth], bdepths[depth] };
|
||||
return ret;
|
||||
*frame = ret;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Frame Compression ///
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef struct {
|
||||
uint8_t * next;
|
||||
size_t size;
|
||||
} MsfBufferHeader;
|
||||
|
||||
static inline int msf_put_code(uint8_t * * writeHead, uint32_t * blockBits, int len, uint32_t code) {
|
||||
static inline void msf_put_code(uint8_t * * writeHead, uint32_t * blockBits, int len, uint32_t code) {
|
||||
//insert new code into block buffer
|
||||
int idx = *blockBits / 8;
|
||||
int bit = *blockBits % 8;
|
||||
|
@ -308,8 +381,6 @@ static inline int msf_put_code(uint8_t * * writeHead, uint32_t * blockBits, int
|
|||
(*writeHead)[0] = 255;
|
||||
memset((*writeHead) + 4, 0, 256);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
|
@ -324,30 +395,29 @@ static inline void msf_lzw_reset(MsfStridedList * lzw, int tableSize, int stride
|
|||
lzw->stride = stride;
|
||||
}
|
||||
|
||||
static uint8_t * msf_compress_frame(void * allocContext, int width, int height, int centiSeconds,
|
||||
MsfCookedFrame frame, MsfCookedFrame previous, uint8_t * used)
|
||||
static MsfGifBuffer * msf_compress_frame(void * allocContext, int width, int height, int centiSeconds,
|
||||
MsfCookedFrame frame, MsfGifState * handle, uint8_t * used, int16_t * lzwMem)
|
||||
{ MsfTimeFunc
|
||||
//NOTE: we reserve enough memory for theoretical the worst case upfront because it's a reasonable amount,
|
||||
// and prevents us from ever having to check size or realloc during compression
|
||||
int maxBufSize = sizeof(MsfBufferHeader) + 32 + 256 * 3 + width * height * 3 / 2; //headers + color table + data
|
||||
uint8_t * allocation = (uint8_t *) MSF_GIF_MALLOC(allocContext, maxBufSize);
|
||||
if (!allocation) { return NULL; }
|
||||
uint8_t * writeBase = allocation + sizeof(MsfBufferHeader);
|
||||
uint8_t * writeHead = writeBase;
|
||||
int lzwAllocSize = 4096 * (frame.count + 1) * sizeof(int16_t);
|
||||
MsfStridedList lzw = { (int16_t *) MSF_GIF_MALLOC(allocContext, lzwAllocSize) };
|
||||
if (!lzw.data) { MSF_GIF_FREE(allocContext, allocation, maxBufSize); return NULL; }
|
||||
int maxBufSize = offsetof(MsfGifBuffer, data) + 32 + 256 * 3 + width * height * 3 / 2; //headers + color table + data
|
||||
MsfGifBuffer * buffer = (MsfGifBuffer *) MSF_GIF_MALLOC(allocContext, maxBufSize);
|
||||
if (!buffer) { return NULL; }
|
||||
uint8_t * writeHead = buffer->data;
|
||||
MsfStridedList lzw = { lzwMem };
|
||||
|
||||
//allocate tlb
|
||||
int totalBits = frame.rbits + frame.gbits + frame.bbits;
|
||||
int tlbSize = 1 << totalBits;
|
||||
uint8_t tlb[1 << 16]; //only 64k, so stack allocating is fine
|
||||
int tlbSize = (1 << totalBits) + 1;
|
||||
uint8_t tlb[(1 << 16) + 1]; //only 64k, so stack allocating is fine
|
||||
|
||||
//generate palette
|
||||
typedef struct { uint8_t r, g, b; } Color3;
|
||||
Color3 table[256] = { {0} };
|
||||
int tableIdx = 1; //we start counting at 1 because 0 is the transparent color
|
||||
MsfTimeLoop("table") for (int i = 0; i < tlbSize; ++i) {
|
||||
//transparent is always last in the table
|
||||
tlb[tlbSize-1] = 0;
|
||||
MsfTimeLoop("table") for (int i = 0; i < tlbSize-1; ++i) {
|
||||
if (used[i]) {
|
||||
tlb[i] = tableIdx;
|
||||
int rmask = (1 << frame.rbits) - 1;
|
||||
|
@ -363,19 +433,32 @@ static uint8_t * msf_compress_frame(void * allocContext, int width, int height,
|
|||
table[tableIdx].r = r | r >> frame.rbits | r >> (frame.rbits * 2) | r >> (frame.rbits * 3);
|
||||
table[tableIdx].g = g | g >> frame.gbits | g >> (frame.gbits * 2) | g >> (frame.gbits * 3);
|
||||
table[tableIdx].b = b | b >> frame.bbits | b >> (frame.bbits * 2) | b >> (frame.bbits * 3);
|
||||
if (msf_gif_bgra_flag) {
|
||||
uint8_t temp = table[tableIdx].r;
|
||||
table[tableIdx].r = table[tableIdx].b;
|
||||
table[tableIdx].b = temp;
|
||||
}
|
||||
++tableIdx;
|
||||
}
|
||||
}
|
||||
int hasTransparentPixels = used[tlbSize-1];
|
||||
|
||||
//SPEC: "Because of some algorithmic constraints however, black & white images which have one color bit
|
||||
// must be indicated as having a code size of 2."
|
||||
int tableBits = msf_imax(2, msf_bit_log(tableIdx - 1));
|
||||
int tableSize = 1 << tableBits;
|
||||
//NOTE: we don't just compare `depth` field here because it will be wrong for the first frame and we will segfault
|
||||
MsfCookedFrame previous = handle->previousFrame;
|
||||
int hasSamePal = frame.rbits == previous.rbits && frame.gbits == previous.gbits && frame.bbits == previous.bbits;
|
||||
int framesCompatible = hasSamePal && !hasTransparentPixels;
|
||||
|
||||
//NOTE: because __attribute__((__packed__)) is annoyingly compiler-specific, we do this unreadable weirdness
|
||||
char headerBytes[19] = "\x21\xF9\x04\x05\0\0\0\0" "\x2C\0\0\0\0\0\0\0\0\x80";
|
||||
//NOTE: we need to check the frame number because if we reach into the buffer prior to the first frame,
|
||||
// we'll just clobber the file header instead, which is a bug
|
||||
if (hasTransparentPixels && handle->framesSubmitted > 0) {
|
||||
handle->listTail->data[3] = 0x09; //set the previous frame's disposal to background, so transparency is possible
|
||||
}
|
||||
memcpy(&headerBytes[4], ¢iSeconds, 2);
|
||||
memcpy(&headerBytes[13], &width, 2);
|
||||
memcpy(&headerBytes[15], &height, 2);
|
||||
|
@ -397,12 +480,10 @@ static uint8_t * msf_compress_frame(void * allocContext, int width, int height,
|
|||
msf_lzw_reset(&lzw, tableSize, tableIdx);
|
||||
msf_put_code(&writeHead, &blockBits, msf_bit_log(lzw.len - 1), tableSize);
|
||||
|
||||
int lastCode = hasSamePal && frame.pixels[0] == previous.pixels[0]? 0 : tlb[frame.pixels[0]];
|
||||
int lastCode = framesCompatible && frame.pixels[0] == previous.pixels[0]? 0 : tlb[frame.pixels[0]];
|
||||
MsfTimeLoop("compress") for (int i = 1; i < width * height; ++i) {
|
||||
//PERF: branching vs. branchless version of this line is observed to have no discernable impact on speed
|
||||
int color = hasSamePal && frame.pixels[i] == previous.pixels[i]? 0 : tlb[frame.pixels[i]];
|
||||
//PERF: branchless version must use && otherwise it will segfault on frame 1, but it's well-predicted so OK
|
||||
// int color = (!(hasSamePal && frame.pixels[i] == previous.pixels[i])) * tlb[frame.pixels[i]];
|
||||
int color = framesCompatible && frame.pixels[i] == previous.pixels[i]? 0 : tlb[frame.pixels[i]];
|
||||
int code = (&lzw.data[lastCode * lzw.stride])[color];
|
||||
if (code < 0) {
|
||||
//write to code stream
|
||||
|
@ -424,9 +505,6 @@ static uint8_t * msf_compress_frame(void * allocContext, int width, int height,
|
|||
}
|
||||
}
|
||||
|
||||
MSF_GIF_FREE(allocContext, lzw.data, lzwAllocSize);
|
||||
MSF_GIF_FREE(allocContext, previous.pixels, width * height * sizeof(uint32_t));
|
||||
|
||||
//write code for leftover index buffer contents, then the end code
|
||||
msf_put_code(&writeHead, &blockBits, msf_imin(12, msf_bit_log(lzw.len - 1)), lastCode);
|
||||
msf_put_code(&writeHead, &blockBits, msf_imin(12, msf_bit_log(lzw.len)), tableSize + 1);
|
||||
|
@ -439,38 +517,72 @@ static uint8_t * msf_compress_frame(void * allocContext, int width, int height,
|
|||
}
|
||||
*writeHead++ = 0; //terminating block
|
||||
|
||||
//filling in buffer header and shrink buffer to fit data
|
||||
MsfBufferHeader * header = (MsfBufferHeader *) allocation;
|
||||
header->next = NULL;
|
||||
header->size = writeHead - writeBase;
|
||||
uint8_t * moved = (uint8_t *) MSF_GIF_REALLOC(allocContext, allocation, maxBufSize, writeHead - allocation);
|
||||
if (!moved) { MSF_GIF_FREE(allocContext, allocation, maxBufSize); return NULL; }
|
||||
//fill in buffer header and shrink buffer to fit data
|
||||
buffer->next = NULL;
|
||||
buffer->size = writeHead - buffer->data;
|
||||
MsfGifBuffer * moved =
|
||||
(MsfGifBuffer *) MSF_GIF_REALLOC(allocContext, buffer, maxBufSize, offsetof(MsfGifBuffer, data) + buffer->size);
|
||||
if (!moved) { MSF_GIF_FREE(allocContext, buffer, maxBufSize); return NULL; }
|
||||
return moved;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Incremental API ///
|
||||
/// To-memory API ///
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const int lzwAllocSize = 4096 * 256 * sizeof(int16_t);
|
||||
|
||||
//NOTE: by C standard library conventions, freeing NULL should be a no-op,
|
||||
// but just in case the user's custom free doesn't follow that rule, we do null checks on our end as well.
|
||||
static void msf_free_gif_state(MsfGifState * handle) {
|
||||
if (handle->previousFrame.pixels) MSF_GIF_FREE(handle->customAllocatorContext, handle->previousFrame.pixels,
|
||||
handle->width * handle->height * sizeof(uint32_t));
|
||||
if (handle->currentFrame.pixels) MSF_GIF_FREE(handle->customAllocatorContext, handle->currentFrame.pixels,
|
||||
handle->width * handle->height * sizeof(uint32_t));
|
||||
if (handle->lzwMem) MSF_GIF_FREE(handle->customAllocatorContext, handle->lzwMem, lzwAllocSize);
|
||||
for (MsfGifBuffer * node = handle->listHead; node;) {
|
||||
MsfGifBuffer * next = node->next; //NOTE: we have to copy the `next` pointer BEFORE freeing the node holding it
|
||||
MSF_GIF_FREE(handle->customAllocatorContext, node, offsetof(MsfGifBuffer, data) + node->size);
|
||||
node = next;
|
||||
}
|
||||
handle->listHead = NULL; //this implicitly marks the handle as invalid until the next msf_gif_begin() call
|
||||
}
|
||||
|
||||
int msf_gif_begin(MsfGifState * handle, int width, int height) { MsfTimeFunc
|
||||
//NOTE: we cannot stomp the entire struct to zero because we must preserve `customAllocatorContext`.
|
||||
MsfCookedFrame empty = {0}; //god I hate MSVC...
|
||||
handle->previousFrame = empty;
|
||||
handle->currentFrame = empty;
|
||||
handle->width = width;
|
||||
handle->height = height;
|
||||
handle->framesSubmitted = 0;
|
||||
|
||||
//allocate memory for LZW buffer
|
||||
//NOTE: Unfortunately we can't just use stack memory for the LZW table because it's 2MB,
|
||||
// which is more stack space than most operating systems give by default,
|
||||
// and we can't realistically expect users to be willing to override that just to use our library,
|
||||
// so we have to allocate this on the heap.
|
||||
handle->lzwMem = (int16_t *) MSF_GIF_MALLOC(handle->customAllocatorContext, lzwAllocSize);
|
||||
handle->previousFrame.pixels =
|
||||
(uint32_t *) MSF_GIF_MALLOC(handle->customAllocatorContext, handle->width * handle->height * sizeof(uint32_t));
|
||||
handle->currentFrame.pixels =
|
||||
(uint32_t *) MSF_GIF_MALLOC(handle->customAllocatorContext, handle->width * handle->height * sizeof(uint32_t));
|
||||
|
||||
//setup header buffer header (lol)
|
||||
handle->listHead = (uint8_t *) MSF_GIF_MALLOC(handle->customAllocatorContext, sizeof(MsfBufferHeader) + 32);
|
||||
if (!handle->listHead) { return 0; }
|
||||
handle->listHead = (MsfGifBuffer *) MSF_GIF_MALLOC(handle->customAllocatorContext, offsetof(MsfGifBuffer, data) + 32);
|
||||
if (!handle->listHead || !handle->lzwMem || !handle->previousFrame.pixels || !handle->currentFrame.pixels) {
|
||||
msf_free_gif_state(handle);
|
||||
return 0;
|
||||
}
|
||||
handle->listTail = handle->listHead;
|
||||
MsfBufferHeader * header = (MsfBufferHeader *) handle->listHead;
|
||||
header->next = NULL;
|
||||
header->size = 32;
|
||||
handle->listHead->next = NULL;
|
||||
handle->listHead->size = 32;
|
||||
|
||||
//NOTE: because __attribute__((__packed__)) is annoyingly compiler-specific, we do this unreadable weirdness
|
||||
char headerBytes[33] = "GIF89a\0\0\0\0\x10\0\0" "\x21\xFF\x0BNETSCAPE2.0\x03\x01\0\0\0";
|
||||
char headerBytes[33] = "GIF89a\0\0\0\0\x70\0\0" "\x21\xFF\x0BNETSCAPE2.0\x03\x01\0\0\0";
|
||||
memcpy(&headerBytes[6], &width, 2);
|
||||
memcpy(&headerBytes[8], &height, 2);
|
||||
memcpy(handle->listHead + sizeof(MsfBufferHeader), headerBytes, 32);
|
||||
memcpy(handle->listHead->data, headerBytes, 32);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -482,86 +594,83 @@ int msf_gif_frame(MsfGifState * handle, uint8_t * pixelData, int centiSecondsPer
|
|||
if (pitchInBytes == 0) pitchInBytes = handle->width * 4;
|
||||
if (pitchInBytes < 0) pixelData -= pitchInBytes * (handle->height - 1);
|
||||
|
||||
uint8_t used[1 << 16]; //only 64k, so stack allocating is fine
|
||||
MsfCookedFrame frame =
|
||||
msf_cook_frame(handle->customAllocatorContext, pixelData, used, handle->width, handle->height, pitchInBytes,
|
||||
uint8_t used[(1 << 16) + 1]; //only 64k, so stack allocating is fine
|
||||
msf_cook_frame(&handle->currentFrame, pixelData, used, handle->width, handle->height, pitchInBytes,
|
||||
msf_imin(maxBitDepth, handle->previousFrame.depth + 160 / msf_imax(1, handle->previousFrame.count)));
|
||||
//TODO: de-duplicate cleanup code
|
||||
if (!frame.pixels) {
|
||||
MSF_GIF_FREE(handle->customAllocatorContext,
|
||||
handle->previousFrame.pixels, handle->width * handle->height * sizeof(uint32_t));
|
||||
for (uint8_t * node = handle->listHead; node;) {
|
||||
MsfBufferHeader * header = (MsfBufferHeader *) node;
|
||||
node = header->next;
|
||||
MSF_GIF_FREE(handle->customAllocatorContext, header, sizeof(MsfBufferHeader) + header->size);
|
||||
}
|
||||
handle->listHead = handle->listTail = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t * buffer = msf_compress_frame(handle->customAllocatorContext,
|
||||
handle->width, handle->height, centiSecondsPerFame, frame, handle->previousFrame, used);
|
||||
((MsfBufferHeader *) handle->listTail)->next = buffer;
|
||||
MsfGifBuffer * buffer = msf_compress_frame(handle->customAllocatorContext, handle->width, handle->height,
|
||||
centiSecondsPerFame, handle->currentFrame, handle, used, handle->lzwMem);
|
||||
if (!buffer) { msf_free_gif_state(handle); return 0; }
|
||||
handle->listTail->next = buffer;
|
||||
handle->listTail = buffer;
|
||||
if (!buffer) {
|
||||
MSF_GIF_FREE(handle->customAllocatorContext, frame.pixels, handle->width * handle->height * sizeof(uint32_t));
|
||||
MSF_GIF_FREE(handle->customAllocatorContext,
|
||||
handle->previousFrame.pixels, handle->width * handle->height * sizeof(uint32_t));
|
||||
for (uint8_t * node = handle->listHead; node;) {
|
||||
MsfBufferHeader * header = (MsfBufferHeader *) node;
|
||||
node = header->next;
|
||||
MSF_GIF_FREE(handle->customAllocatorContext, header, sizeof(MsfBufferHeader) + header->size);
|
||||
}
|
||||
handle->listHead = handle->listTail = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
handle->previousFrame = frame;
|
||||
//swap current and previous frames
|
||||
MsfCookedFrame tmp = handle->previousFrame;
|
||||
handle->previousFrame = handle->currentFrame;
|
||||
handle->currentFrame = tmp;
|
||||
|
||||
handle->framesSubmitted += 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
MsfGifResult msf_gif_end(MsfGifState * handle) { MsfTimeFunc
|
||||
if (!handle->listHead) { MsfGifResult empty = {0}; return empty; }
|
||||
|
||||
MSF_GIF_FREE(handle->customAllocatorContext,
|
||||
handle->previousFrame.pixels, handle->width * handle->height * sizeof(uint32_t));
|
||||
|
||||
//first pass: determine total size
|
||||
size_t total = 1; //1 byte for trailing marker
|
||||
for (uint8_t * node = handle->listHead; node;) {
|
||||
MsfBufferHeader * header = (MsfBufferHeader *) node;
|
||||
node = header->next;
|
||||
total += header->size;
|
||||
}
|
||||
for (MsfGifBuffer * node = handle->listHead; node; node = node->next) { total += node->size; }
|
||||
|
||||
//second pass: write data
|
||||
uint8_t * buffer = (uint8_t *) MSF_GIF_MALLOC(handle->customAllocatorContext, total);
|
||||
if (buffer) {
|
||||
uint8_t * writeHead = buffer;
|
||||
for (uint8_t * node = handle->listHead; node;) {
|
||||
MsfBufferHeader * header = (MsfBufferHeader *) node;
|
||||
memcpy(writeHead, node + sizeof(MsfBufferHeader), header->size);
|
||||
writeHead += header->size;
|
||||
node = header->next;
|
||||
for (MsfGifBuffer * node = handle->listHead; node; node = node->next) {
|
||||
memcpy(writeHead, node->data, node->size);
|
||||
writeHead += node->size;
|
||||
}
|
||||
*writeHead++ = 0x3B;
|
||||
}
|
||||
|
||||
//third pass: free buffers
|
||||
for (uint8_t * node = handle->listHead; node;) {
|
||||
MsfBufferHeader * header = (MsfBufferHeader *) node;
|
||||
node = header->next;
|
||||
MSF_GIF_FREE(handle->customAllocatorContext, header, sizeof(MsfBufferHeader) + header->size);
|
||||
}
|
||||
msf_free_gif_state(handle);
|
||||
|
||||
MsfGifResult ret = { buffer, total, total, handle->customAllocatorContext };
|
||||
return ret;
|
||||
}
|
||||
|
||||
void msf_gif_free(MsfGifResult result) {
|
||||
void msf_gif_free(MsfGifResult result) { MsfTimeFunc
|
||||
if (result.data) { MSF_GIF_FREE(result.contextPointer, result.data, result.allocSize); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// To-file API ///
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int msf_gif_begin_to_file(MsfGifState * handle, int width, int height, MsfGifFileWriteFunc func, void * filePointer) {
|
||||
handle->fileWriteFunc = func;
|
||||
handle->fileWriteData = filePointer;
|
||||
return msf_gif_begin(handle, width, height);
|
||||
}
|
||||
|
||||
int msf_gif_frame_to_file(MsfGifState * handle, uint8_t * pixelData, int centiSecondsPerFame, int maxBitDepth, int pitchInBytes) {
|
||||
if (!msf_gif_frame(handle, pixelData, centiSecondsPerFame, maxBitDepth, pitchInBytes)) { return 0; }
|
||||
|
||||
//NOTE: this is a somewhat hacky implementation which is not perfectly efficient, but it's good enough for now
|
||||
MsfGifBuffer * head = handle->listHead;
|
||||
if (!handle->fileWriteFunc(head->data, head->size, 1, handle->fileWriteData)) { msf_free_gif_state(handle); return 0; }
|
||||
handle->listHead = head->next;
|
||||
MSF_GIF_FREE(handle->customAllocatorContext, head, offsetof(MsfGifBuffer, data) + head->size);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int msf_gif_end_to_file(MsfGifState * handle) {
|
||||
//NOTE: this is a somewhat hacky implementation which is not perfectly efficient, but it's good enough for now
|
||||
MsfGifResult result = msf_gif_end(handle);
|
||||
int ret = (int) handle->fileWriteFunc(result.data, result.dataSize, 1, handle->fileWriteData);
|
||||
msf_gif_free(result);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif //MSF_GIF_ALREADY_IMPLEMENTED_IN_THIS_TRANSLATION_UNIT
|
||||
#endif //MSF_GIF_IMPL
|
||||
|
||||
|
@ -570,7 +679,7 @@ void msf_gif_free(MsfGifResult result) {
|
|||
This software is available under 2 licenses -- choose whichever you prefer.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE A - MIT License
|
||||
Copyright (c) 2020 Miles Fogle
|
||||
Copyright (c) 2021 Miles Fogle
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
|
|
162
raylib/external/par_shapes.h
vendored
162
raylib/external/par_shapes.h
vendored
|
@ -21,8 +21,7 @@
|
|||
// coordinates (one per vertex). That's it! If you need something fancier,
|
||||
// look elsewhere.
|
||||
//
|
||||
// The MIT License
|
||||
// Copyright (c) 2015 Philip Rideout
|
||||
// Distributed under the MIT License, see bottom of file.
|
||||
|
||||
#ifndef PAR_SHAPES_H
|
||||
#define PAR_SHAPES_H
|
||||
|
@ -32,8 +31,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// Ray: commented to avoid conflict with raylib bool
|
||||
// Ray (@raysan5): Commented to avoid conflict with raylib bool
|
||||
/*
|
||||
#if !defined(_MSC_VER)
|
||||
# include <stdbool.h>
|
||||
|
@ -41,9 +39,9 @@ extern "C" {
|
|||
# if _MSC_VER >= 1800
|
||||
# include <stdbool.h>
|
||||
# else // stdbool.h missing prior to MSVC++ 12.0 (VS2013)
|
||||
//# define bool int
|
||||
//# define true 1
|
||||
//# define false 0
|
||||
# define bool int
|
||||
# define true 1
|
||||
# define false 0
|
||||
# endif
|
||||
#endif
|
||||
*/
|
||||
|
@ -71,6 +69,14 @@ void par_shapes_free_mesh(par_shapes_mesh*);
|
|||
// both 1.0, but they can easily be changed with par_shapes_scale.
|
||||
par_shapes_mesh* par_shapes_create_cylinder(int slices, int stacks);
|
||||
|
||||
// Cone is similar to cylinder but the radius diminishes to zero as Z increases.
|
||||
// Again, height and radius are 1.0, but can be changed with par_shapes_scale.
|
||||
par_shapes_mesh* par_shapes_create_cone(int slices, int stacks);
|
||||
|
||||
// Create a disk of radius 1.0 with texture coordinates and normals by squashing
|
||||
// a cone flat on the Z=0 plane.
|
||||
par_shapes_mesh* par_shapes_create_parametric_disk(int slices, int stacks);
|
||||
|
||||
// Create a donut that sits on the Z=0 plane with the specified inner radius.
|
||||
// The outer radius can be controlled with par_shapes_scale.
|
||||
par_shapes_mesh* par_shapes_create_torus(int slices, int stacks, float radius);
|
||||
|
@ -172,6 +178,17 @@ par_shapes_mesh* par_shapes_weld(par_shapes_mesh const*, float epsilon,
|
|||
// Compute smooth normals by averaging adjacent facet normals.
|
||||
void par_shapes_compute_normals(par_shapes_mesh* m);
|
||||
|
||||
// Global Config ---------------------------------------------------------------
|
||||
|
||||
void par_shapes_set_epsilon_welded_normals(float epsilon);
|
||||
void par_shapes_set_epsilon_degenerate_sphere(float epsilon);
|
||||
|
||||
// Advanced --------------------------------------------------------------------
|
||||
|
||||
void par_shapes__compute_welded_normals(par_shapes_mesh* m);
|
||||
void par_shapes__connect(par_shapes_mesh* scene, par_shapes_mesh* cylinder,
|
||||
int slices);
|
||||
|
||||
#ifndef PAR_PI
|
||||
#define PAR_PI (3.14159265359)
|
||||
#define PAR_MIN(a, b) (a > b ? b : a)
|
||||
|
@ -205,11 +222,15 @@ void par_shapes_compute_normals(par_shapes_mesh* m);
|
|||
#include <math.h>
|
||||
#include <errno.h>
|
||||
|
||||
static float par_shapes__epsilon_welded_normals = 0.001;
|
||||
static float par_shapes__epsilon_degenerate_sphere = 0.0001;
|
||||
|
||||
static void par_shapes__sphere(float const* uv, float* xyz, void*);
|
||||
static void par_shapes__hemisphere(float const* uv, float* xyz, void*);
|
||||
static void par_shapes__plane(float const* uv, float* xyz, void*);
|
||||
static void par_shapes__klein(float const* uv, float* xyz, void*);
|
||||
static void par_shapes__cylinder(float const* uv, float* xyz, void*);
|
||||
static void par_shapes__cone(float const* uv, float* xyz, void*);
|
||||
static void par_shapes__torus(float const* uv, float* xyz, void*);
|
||||
static void par_shapes__trefoil(float const* uv, float* xyz, void*);
|
||||
|
||||
|
@ -298,11 +319,12 @@ static float par_shapes__sqrdist3(float const* a, float const* b)
|
|||
return dx * dx + dy * dy + dz * dz;
|
||||
}
|
||||
|
||||
static void par_shapes__compute_welded_normals(par_shapes_mesh* m)
|
||||
void par_shapes__compute_welded_normals(par_shapes_mesh* m)
|
||||
{
|
||||
const float epsilon = par_shapes__epsilon_welded_normals;
|
||||
m->normals = PAR_MALLOC(float, m->npoints * 3);
|
||||
PAR_SHAPES_T* weldmap = PAR_MALLOC(PAR_SHAPES_T, m->npoints);
|
||||
par_shapes_mesh* welded = par_shapes_weld(m, 0.01, weldmap);
|
||||
par_shapes_mesh* welded = par_shapes_weld(m, epsilon, weldmap);
|
||||
par_shapes_compute_normals(welded);
|
||||
float* pdst = m->normals;
|
||||
for (int i = 0; i < m->npoints; i++, pdst += 3) {
|
||||
|
@ -325,6 +347,24 @@ par_shapes_mesh* par_shapes_create_cylinder(int slices, int stacks)
|
|||
stacks, 0);
|
||||
}
|
||||
|
||||
par_shapes_mesh* par_shapes_create_cone(int slices, int stacks)
|
||||
{
|
||||
if (slices < 3 || stacks < 1) {
|
||||
return 0;
|
||||
}
|
||||
return par_shapes_create_parametric(par_shapes__cone, slices,
|
||||
stacks, 0);
|
||||
}
|
||||
|
||||
par_shapes_mesh* par_shapes_create_parametric_disk(int slices, int stacks)
|
||||
{
|
||||
par_shapes_mesh* m = par_shapes_create_cone(slices, stacks);
|
||||
if (m) {
|
||||
par_shapes_scale(m, 1.0f, 1.0f, 0.0f);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
par_shapes_mesh* par_shapes_create_parametric_sphere(int slices, int stacks)
|
||||
{
|
||||
if (slices < 3 || stacks < 3) {
|
||||
|
@ -332,7 +372,7 @@ par_shapes_mesh* par_shapes_create_parametric_sphere(int slices, int stacks)
|
|||
}
|
||||
par_shapes_mesh* m = par_shapes_create_parametric(par_shapes__sphere,
|
||||
slices, stacks, 0);
|
||||
par_shapes_remove_degenerate(m, 0.0001);
|
||||
par_shapes_remove_degenerate(m, par_shapes__epsilon_degenerate_sphere);
|
||||
return m;
|
||||
}
|
||||
|
||||
|
@ -343,7 +383,7 @@ par_shapes_mesh* par_shapes_create_hemisphere(int slices, int stacks)
|
|||
}
|
||||
par_shapes_mesh* m = par_shapes_create_parametric(par_shapes__hemisphere,
|
||||
slices, stacks, 0);
|
||||
par_shapes_remove_degenerate(m, 0.0001);
|
||||
par_shapes_remove_degenerate(m, par_shapes__epsilon_degenerate_sphere);
|
||||
return m;
|
||||
}
|
||||
|
||||
|
@ -579,6 +619,15 @@ static void par_shapes__cylinder(float const* uv, float* xyz, void* userdata)
|
|||
xyz[2] = uv[0];
|
||||
}
|
||||
|
||||
static void par_shapes__cone(float const* uv, float* xyz, void* userdata)
|
||||
{
|
||||
float r = 1.0f - uv[0];
|
||||
float theta = uv[1] * 2 * PAR_PI;
|
||||
xyz[0] = r * sinf(theta);
|
||||
xyz[1] = r * cosf(theta);
|
||||
xyz[2] = uv[0];
|
||||
}
|
||||
|
||||
static void par_shapes__torus(float const* uv, float* xyz, void* userdata)
|
||||
{
|
||||
float major = 1;
|
||||
|
@ -620,6 +669,14 @@ static void par_shapes__trefoil(float const* uv, float* xyz, void* userdata)
|
|||
xyz[2] = z + d * ww[2] * sin(v);
|
||||
}
|
||||
|
||||
void par_shapes_set_epsilon_welded_normals(float epsilon) {
|
||||
par_shapes__epsilon_welded_normals = epsilon;
|
||||
}
|
||||
|
||||
void par_shapes_set_epsilon_degenerate_sphere(float epsilon) {
|
||||
par_shapes__epsilon_degenerate_sphere = epsilon;
|
||||
}
|
||||
|
||||
void par_shapes_merge(par_shapes_mesh* dst, par_shapes_mesh const* src)
|
||||
{
|
||||
PAR_SHAPES_T offset = dst->npoints;
|
||||
|
@ -744,15 +801,15 @@ void par_shapes_rotate(par_shapes_mesh* mesh, float radians, float const* axis)
|
|||
p[1] = y;
|
||||
p[2] = z;
|
||||
}
|
||||
p = mesh->normals;
|
||||
if (p) {
|
||||
for (int i = 0; i < mesh->npoints; i++, p += 3) {
|
||||
float x = col0[0] * p[0] + col1[0] * p[1] + col2[0] * p[2];
|
||||
float y = col0[1] * p[0] + col1[1] * p[1] + col2[1] * p[2];
|
||||
float z = col0[2] * p[0] + col1[2] * p[1] + col2[2] * p[2];
|
||||
p[0] = x;
|
||||
p[1] = y;
|
||||
p[2] = z;
|
||||
float* n = mesh->normals;
|
||||
if (n) {
|
||||
for (int i = 0; i < mesh->npoints; i++, n += 3) {
|
||||
float x = col0[0] * n[0] + col1[0] * n[1] + col2[0] * n[2];
|
||||
float y = col0[1] * n[0] + col1[1] * n[1] + col2[1] * n[2];
|
||||
float z = col0[2] * n[0] + col1[2] * n[1] + col2[2] * n[2];
|
||||
n[0] = x;
|
||||
n[1] = y;
|
||||
n[2] = z;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -765,6 +822,27 @@ void par_shapes_scale(par_shapes_mesh* m, float x, float y, float z)
|
|||
*points++ *= y;
|
||||
*points++ *= z;
|
||||
}
|
||||
float* n = m->normals;
|
||||
if (n && !(x == y && y == z)) {
|
||||
bool x_zero = x == 0;
|
||||
bool y_zero = y == 0;
|
||||
bool z_zero = z == 0;
|
||||
if (!x_zero && !y_zero && !z_zero) {
|
||||
x = 1.0f / x;
|
||||
y = 1.0f / y;
|
||||
z = 1.0f / z;
|
||||
} else {
|
||||
x = x_zero && !y_zero && !z_zero;
|
||||
y = y_zero && !x_zero && !z_zero;
|
||||
z = z_zero && !x_zero && !y_zero;
|
||||
}
|
||||
for (int i = 0; i < m->npoints; i++, n += 3) {
|
||||
n[0] *= x;
|
||||
n[1] *= y;
|
||||
n[2] *= z;
|
||||
par_shapes__normalize3(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void par_shapes_merge_and_free(par_shapes_mesh* dst, par_shapes_mesh* src)
|
||||
|
@ -1098,8 +1176,8 @@ static par_shapes_mesh* par_shapes__apply_turtle(par_shapes_mesh* mesh,
|
|||
return m;
|
||||
}
|
||||
|
||||
static void par_shapes__connect(par_shapes_mesh* scene,
|
||||
par_shapes_mesh* cylinder, int slices)
|
||||
void par_shapes__connect(par_shapes_mesh* scene, par_shapes_mesh* cylinder,
|
||||
int slices)
|
||||
{
|
||||
int stacks = 1;
|
||||
int npoints = (slices + 1) * (stacks + 1);
|
||||
|
@ -1118,7 +1196,8 @@ static void par_shapes__connect(par_shapes_mesh* scene,
|
|||
// Create the new triangle list.
|
||||
int ntriangles = scene->ntriangles + 2 * slices * stacks;
|
||||
PAR_SHAPES_T* triangles = PAR_MALLOC(PAR_SHAPES_T, ntriangles * 3);
|
||||
memcpy(triangles, scene->triangles, 2 * scene->ntriangles * 3);
|
||||
memcpy(triangles, scene->triangles,
|
||||
sizeof(PAR_SHAPES_T) * scene->ntriangles * 3);
|
||||
int v = scene->npoints - (slices + 1);
|
||||
PAR_SHAPES_T* face = triangles + scene->ntriangles * 3;
|
||||
for (int stack = 0; stack < stacks; stack++) {
|
||||
|
@ -1154,7 +1233,7 @@ par_shapes_mesh* par_shapes_create_lsystem(char const* text, int slices,
|
|||
while (cmd) {
|
||||
char *arg = strtok(0, " ");
|
||||
if (!arg) {
|
||||
//puts("lsystem error: unexpected end of program.");
|
||||
puts("lsystem error: unexpected end of program.");
|
||||
break;
|
||||
}
|
||||
if (!strcmp(cmd, "rule")) {
|
||||
|
@ -1208,7 +1287,6 @@ par_shapes_mesh* par_shapes_create_lsystem(char const* text, int slices,
|
|||
|
||||
// For testing purposes, dump out the parsed program.
|
||||
#ifdef TEST_PARSE
|
||||
/*
|
||||
for (int i = 0; i < nrules; i++) {
|
||||
par_shapes__rule rule = rules[i];
|
||||
printf("rule %s.%d\n", rule.name, rule.weight);
|
||||
|
@ -1217,7 +1295,6 @@ par_shapes_mesh* par_shapes_create_lsystem(char const* text, int slices,
|
|||
printf("\t%s %s\n", cmd.cmd, cmd.arg);
|
||||
}
|
||||
}
|
||||
*/
|
||||
#endif
|
||||
|
||||
// Instantiate the aggregated shape and the template shapes.
|
||||
|
@ -1258,7 +1335,8 @@ par_shapes_mesh* par_shapes_create_lsystem(char const* text, int slices,
|
|||
|
||||
par_shapes__command* cmd = rule->commands + (frame->pc++);
|
||||
#ifdef DUMP_TRACE
|
||||
//printf("%5s %5s %5s:%d %03d\n", cmd->cmd, cmd->arg, rule->name, frame->pc - 1, stackptr);
|
||||
printf("%5s %5s %5s:%d %03d\n", cmd->cmd, cmd->arg, rule->name,
|
||||
frame->pc - 1, stackptr);
|
||||
#endif
|
||||
|
||||
float value;
|
||||
|
@ -1620,7 +1698,7 @@ static void par_shapes__weld_points(par_shapes_mesh* mesh, int gridsize,
|
|||
PAR_SHAPES_T binvalue = *(bins + binindex);
|
||||
if (binvalue > 0) {
|
||||
if (nbins == 8) {
|
||||
//printf("Epsilon value is too large.\n");
|
||||
printf("Epsilon value is too large.\n");
|
||||
break;
|
||||
}
|
||||
nearby[nbins++] = binindex;
|
||||
|
@ -1632,8 +1710,9 @@ static void par_shapes__weld_points(par_shapes_mesh* mesh, int gridsize,
|
|||
// Check for colocated points in each nearby bin.
|
||||
for (int b = 0; b < nbins; b++) {
|
||||
int binindex = nearby[b];
|
||||
PAR_SHAPES_T binvalue = *(bins + binindex);
|
||||
PAR_SHAPES_T binvalue = bins[binindex];
|
||||
PAR_SHAPES_T nindex = binvalue - 1;
|
||||
assert(nindex < mesh->npoints);
|
||||
while (true) {
|
||||
|
||||
// If this isn't "self" and it's colocated, then weld it!
|
||||
|
@ -1699,6 +1778,9 @@ static void par_shapes__weld_points(par_shapes_mesh* mesh, int gridsize,
|
|||
PAR_SHAPES_T b = weldmap[tsrc[1]];
|
||||
PAR_SHAPES_T c = weldmap[tsrc[2]];
|
||||
if (a != b && a != c && b != c) {
|
||||
assert(a < mesh->npoints);
|
||||
assert(b < mesh->npoints);
|
||||
assert(c < mesh->npoints);
|
||||
*tdst++ = a;
|
||||
*tdst++ = b;
|
||||
*tdst++ = c;
|
||||
|
@ -2049,3 +2131,25 @@ void par_shapes_remove_degenerate(par_shapes_mesh* mesh, float mintriarea)
|
|||
|
||||
#endif // PAR_SHAPES_IMPLEMENTATION
|
||||
#endif // PAR_SHAPES_H
|
||||
|
||||
// par_shapes is distributed under the MIT license:
|
||||
//
|
||||
// Copyright (c) 2019 Philip Rideout
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
|
21
raylib/external/sdefl.h
vendored
21
raylib/external/sdefl.h
vendored
|
@ -1,5 +1,4 @@
|
|||
/*
|
||||
# Small Deflate
|
||||
/*# Small Deflate
|
||||
`sdefl` is a small bare bone lossless compression library in ANSI C (ISO C90)
|
||||
which implements the Deflate (RFC 1951) compressed data format specification standard.
|
||||
It is mainly tuned to get as much speed and compression ratio from as little code
|
||||
|
@ -33,16 +32,16 @@ this file implementation in *one* C or C++ file to prevent collisions.
|
|||
|
||||
| Compressor name | Compression| Decompress.| Compr. size | Ratio |
|
||||
| ------------------------| -----------| -----------| ----------- | ----- |
|
||||
| sdefl 1.0 -0 | 127 MB/s | 233 MB/s | 40004116 | 39.88 |
|
||||
| sdefl 1.0 -1 | 111 MB/s | 259 MB/s | 38940674 | 38.82 |
|
||||
| sdefl 1.0 -5 | 45 MB/s | 275 MB/s | 36577183 | 36.46 |
|
||||
| sdefl 1.0 -7 | 38 MB/s | 276 MB/s | 36523781 | 36.41 |
|
||||
| zlib 1.2.11 -1 | 72 MB/s | 307 MB/s | 42298774 | 42.30 |
|
||||
| zlib 1.2.11 -6 | 24 MB/s | 313 MB/s | 36548921 | 36.55 |
|
||||
| zlib 1.2.11 -9 | 20 MB/s | 314 MB/s | 36475792 | 36.48 |
|
||||
| miniz 1.0 -1 | 122 MB/s | 208 MB/s | 48510028 | 48.51 |
|
||||
| miniz 1.0 -6 | 27 MB/s | 260 MB/s | 36513697 | 36.51 |
|
||||
| miniz 1.0 -9 | 23 MB/s | 261 MB/s | 36460101 | 36.46 |
|
||||
| zlib 1.2.11 -1 | 72 MB/s | 307 MB/s | 42298774 | 42.30 |
|
||||
| zlib 1.2.11 -6 | 24 MB/s | 313 MB/s | 36548921 | 36.55 |
|
||||
| zlib 1.2.11 -9 | 20 MB/s | 314 MB/s | 36475792 | 36.48 |
|
||||
| sdefl 1.0 -0 | 127 MB/s | 371 MB/s | 40004116 | 39.88 |
|
||||
| sdefl 1.0 -1 | 111 MB/s | 398 MB/s | 38940674 | 38.82 |
|
||||
| sdefl 1.0 -5 | 45 MB/s | 420 MB/s | 36577183 | 36.46 |
|
||||
| sdefl 1.0 -7 | 38 MB/s | 423 MB/s | 36523781 | 36.41 |
|
||||
| libdeflate 1.3 -1 | 147 MB/s | 667 MB/s | 39597378 | 39.60 |
|
||||
| libdeflate 1.3 -6 | 69 MB/s | 689 MB/s | 36648318 | 36.65 |
|
||||
| libdeflate 1.3 -9 | 13 MB/s | 672 MB/s | 35197141 | 35.20 |
|
||||
|
@ -398,8 +397,8 @@ sdefl_precode(struct sdefl_symcnt *cnt, unsigned *freqs, unsigned *items,
|
|||
if (offlen[cnt->off - 1]) break;
|
||||
|
||||
total = (unsigned)(cnt->lit + cnt->off);
|
||||
memcpy(lens, litlen, sizeof(unsigned char) * cnt->lit);
|
||||
memcpy(lens + cnt->lit, offlen, sizeof(unsigned char) * cnt->off);
|
||||
memcpy(lens, litlen, sizeof(unsigned char) * (size_t)cnt->lit);
|
||||
memcpy(lens + cnt->lit, offlen, sizeof(unsigned char) * (size_t)cnt->off);
|
||||
do {
|
||||
unsigned len = lens[run_start];
|
||||
unsigned run_end = run_start;
|
||||
|
|
276
raylib/external/sinfl.h
vendored
276
raylib/external/sinfl.h
vendored
|
@ -33,16 +33,16 @@ this file implementation in *one* C or C++ file to prevent collisions.
|
|||
|
||||
| Compressor name | Compression| Decompress.| Compr. size | Ratio |
|
||||
| ------------------------| -----------| -----------| ----------- | ----- |
|
||||
| sdefl 1.0 -0 | 127 MB/s | 233 MB/s | 40004116 | 39.88 |
|
||||
| sdefl 1.0 -1 | 111 MB/s | 259 MB/s | 38940674 | 38.82 |
|
||||
| sdefl 1.0 -5 | 45 MB/s | 275 MB/s | 36577183 | 36.46 |
|
||||
| sdefl 1.0 -7 | 38 MB/s | 276 MB/s | 36523781 | 36.41 |
|
||||
| zlib 1.2.11 -1 | 72 MB/s | 307 MB/s | 42298774 | 42.30 |
|
||||
| zlib 1.2.11 -6 | 24 MB/s | 313 MB/s | 36548921 | 36.55 |
|
||||
| zlib 1.2.11 -9 | 20 MB/s | 314 MB/s | 36475792 | 36.48 |
|
||||
| miniz 1.0 -1 | 122 MB/s | 208 MB/s | 48510028 | 48.51 |
|
||||
| miniz 1.0 -6 | 27 MB/s | 260 MB/s | 36513697 | 36.51 |
|
||||
| miniz 1.0 -9 | 23 MB/s | 261 MB/s | 36460101 | 36.46 |
|
||||
| zlib 1.2.11 -1 | 72 MB/s | 307 MB/s | 42298774 | 42.30 |
|
||||
| zlib 1.2.11 -6 | 24 MB/s | 313 MB/s | 36548921 | 36.55 |
|
||||
| zlib 1.2.11 -9 | 20 MB/s | 314 MB/s | 36475792 | 36.48 |
|
||||
| sdefl 1.0 -0 | 127 MB/s | 371 MB/s | 40004116 | 39.88 |
|
||||
| sdefl 1.0 -1 | 111 MB/s | 398 MB/s | 38940674 | 38.82 |
|
||||
| sdefl 1.0 -5 | 45 MB/s | 420 MB/s | 36577183 | 36.46 |
|
||||
| sdefl 1.0 -7 | 38 MB/s | 423 MB/s | 36523781 | 36.41 |
|
||||
| libdeflate 1.3 -1 | 147 MB/s | 667 MB/s | 39597378 | 39.60 |
|
||||
| libdeflate 1.3 -6 | 69 MB/s | 689 MB/s | 36648318 | 36.65 |
|
||||
| libdeflate 1.3 -9 | 13 MB/s | 672 MB/s | 35197141 | 35.20 |
|
||||
|
@ -121,12 +121,15 @@ extern "C" {
|
|||
#define SINFL_OFF_TBL_SIZE 402
|
||||
|
||||
struct sinfl {
|
||||
int bits, bitcnt;
|
||||
const unsigned char *bitptr;
|
||||
unsigned long long bitbuf;
|
||||
int bitcnt;
|
||||
|
||||
unsigned lits[SINFL_LIT_TBL_SIZE];
|
||||
unsigned dsts[SINFL_OFF_TBL_SIZE];
|
||||
};
|
||||
extern int sinflate(void *out, const void *in, int size);
|
||||
extern int zsinflate(void *out, const void *in, int size);
|
||||
extern int sinflate(void *out, int cap, const void *in, int size);
|
||||
extern int zsinflate(void *out, int cap, const void *in, int size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -137,6 +140,33 @@ extern int zsinflate(void *out, const void *in, int size);
|
|||
#ifdef SINFL_IMPLEMENTATION
|
||||
|
||||
#include <string.h> /* memcpy, memset */
|
||||
#include <assert.h> /* assert */
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define sinfl_likely(x) __builtin_expect((x),1)
|
||||
#define sinfl_unlikely(x) __builtin_expect((x),0)
|
||||
#else
|
||||
#define sinfl_likely(x) (x)
|
||||
#define sinfl_unlikely(x) (x)
|
||||
#endif
|
||||
|
||||
#ifndef SINFL_NO_SIMD
|
||||
#if __x86_64__ || defined(_WIN32) || defined(_WIN64)
|
||||
#include <emmintrin.h>
|
||||
#define sinfl_char16 __m128i
|
||||
#define sinfl_char16_ld(p) _mm_loadu_si128((const __m128i *)(void*)(p))
|
||||
#define sinfl_char16_str(d,v) _mm_storeu_si128((__m128i*)(void*)(d), v)
|
||||
#define sinfl_char16_char(c) _mm_set1_epi8(c)
|
||||
#elif defined(__arm__) || defined(__aarch64__)
|
||||
#include <arm_neon.h>
|
||||
#define sinfl_char16 uint8x16_t
|
||||
#define sinfl_char16_ld(p) vld1q_u8((const unsigned char*)(p))
|
||||
#define sinfl_char16_str(d,v) vst1q_u8((unsigned char*)(d), v)
|
||||
#define sinfl_char16_char(c) vdupq_n_u8(c)
|
||||
#else
|
||||
#define SINFL_NO_SIMD
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static int
|
||||
sinfl_bsr(unsigned n) {
|
||||
|
@ -147,20 +177,66 @@ sinfl_bsr(unsigned n) {
|
|||
return 31 - __builtin_clz(n);
|
||||
#endif
|
||||
}
|
||||
static unsigned long long
|
||||
sinfl_read64(const void *p) {
|
||||
unsigned long long n;
|
||||
memcpy(&n, p, 8);
|
||||
return n;
|
||||
}
|
||||
#ifndef SINFL_NO_SIMD
|
||||
static unsigned char*
|
||||
sinfl_write128(unsigned char *dst, sinfl_char16 w) {
|
||||
sinfl_char16_str(dst, w);
|
||||
return dst + 8;
|
||||
}
|
||||
static void
|
||||
sinfl_copy128(unsigned char **dst, unsigned char **src) {
|
||||
sinfl_char16 n = sinfl_char16_ld(*src);
|
||||
sinfl_char16_str(*dst, n);
|
||||
*dst += 16, *src += 16;
|
||||
}
|
||||
#else
|
||||
static unsigned char*
|
||||
sinfl_write64(unsigned char *dst, unsigned long long w) {
|
||||
memcpy(dst, &w, 8);
|
||||
return dst + 8;
|
||||
}
|
||||
static void
|
||||
sinfl_copy64(unsigned char **dst, unsigned char **src) {
|
||||
unsigned long long n;
|
||||
memcpy(&n, *src, 8);
|
||||
memcpy(*dst, &n, 8);
|
||||
*dst += 8, *src += 8;
|
||||
}
|
||||
#endif
|
||||
static void
|
||||
sinfl_refill(struct sinfl *s) {
|
||||
s->bitbuf |= sinfl_read64(s->bitptr) << s->bitcnt;
|
||||
s->bitptr += (63 - s->bitcnt) >> 3;
|
||||
s->bitcnt |= 56; /* bitcount is in range [56,63] */
|
||||
}
|
||||
static int
|
||||
sinfl_get(const unsigned char **src, const unsigned char *end, struct sinfl *s,
|
||||
int n) {
|
||||
const unsigned char *in = *src;
|
||||
int v = s->bits & ((1 << n)-1);
|
||||
s->bits >>= n;
|
||||
s->bitcnt = s->bitcnt - n;
|
||||
s->bitcnt = s->bitcnt < 0 ? 0 : s->bitcnt;
|
||||
while (s->bitcnt < 16 && in < end) {
|
||||
s->bits |= (*in++) << s->bitcnt;
|
||||
s->bitcnt += 8;
|
||||
}
|
||||
*src = in;
|
||||
return v;
|
||||
sinfl_peek(struct sinfl *s, int cnt) {
|
||||
assert(cnt >= 0 && cnt <= 56);
|
||||
assert(cnt <= s->bitcnt);
|
||||
return s->bitbuf & ((1ull << cnt) - 1);
|
||||
}
|
||||
static void
|
||||
sinfl_consume(struct sinfl *s, int cnt) {
|
||||
assert(cnt <= s->bitcnt);
|
||||
s->bitbuf >>= cnt;
|
||||
s->bitcnt -= cnt;
|
||||
}
|
||||
static int
|
||||
sinfl__get(struct sinfl *s, int cnt) {
|
||||
int res = sinfl_peek(s, cnt);
|
||||
sinfl_consume(s, cnt);
|
||||
return res;
|
||||
}
|
||||
static int
|
||||
sinfl_get(struct sinfl *s, int cnt) {
|
||||
sinfl_refill(s);
|
||||
return sinfl__get(s, cnt);
|
||||
}
|
||||
struct sinfl_gen {
|
||||
int len;
|
||||
|
@ -276,22 +352,22 @@ sinfl_build(unsigned *tbl, unsigned char *lens, int tbl_bits, int maxlen,
|
|||
}
|
||||
}
|
||||
static int
|
||||
sinfl_decode(const unsigned char **in, const unsigned char *end,
|
||||
struct sinfl *s, const unsigned *tbl, int bit_len) {
|
||||
int idx = s->bits & ((1 << bit_len) - 1);
|
||||
sinfl_decode(struct sinfl *s, const unsigned *tbl, int bit_len) {
|
||||
sinfl_refill(s);
|
||||
{int idx = sinfl_peek(s, bit_len);
|
||||
unsigned key = tbl[idx];
|
||||
if (key & 0x10) {
|
||||
/* sub-table lookup */
|
||||
int len = key & 0x0f;
|
||||
sinfl_get(in, end, s, bit_len);
|
||||
idx = s->bits & ((1 << len)-1);
|
||||
sinfl_consume(s, bit_len);
|
||||
idx = sinfl_peek(s, len);
|
||||
key = tbl[((key >> 16) & 0xffff) + (unsigned)idx];
|
||||
}
|
||||
sinfl_get(in, end, s, key & 0x0f);
|
||||
return (key >> 16) & 0x0fff;
|
||||
sinfl_consume(s, key & 0x0f);
|
||||
return (key >> 16) & 0x0fff;}
|
||||
}
|
||||
static int
|
||||
sinfl_decompress(unsigned char *out, const unsigned char *in, int size) {
|
||||
sinfl_decompress(unsigned char *out, int cap, const unsigned char *in, int size) {
|
||||
static const unsigned char order[] = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
|
||||
static const short dbase[30+2] = {1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,
|
||||
257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577};
|
||||
|
@ -302,19 +378,22 @@ sinfl_decompress(unsigned char *out, const unsigned char *in, int size) {
|
|||
static const unsigned char lbits[29+2] = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,
|
||||
4,4,4,5,5,5,5,0,0,0};
|
||||
|
||||
const unsigned char *oe = out + cap;
|
||||
const unsigned char *e = in + size, *o = out;
|
||||
enum sinfl_states {hdr,stored,fixed,dyn,blk};
|
||||
enum sinfl_states state = hdr;
|
||||
struct sinfl s = {0};
|
||||
int last = 0;
|
||||
|
||||
sinfl_get(&in,e,&s,0); /* buffer input */
|
||||
while (in < e || s.bitcnt) {
|
||||
s.bitptr = in;
|
||||
while (1) {
|
||||
switch (state) {
|
||||
case hdr: {
|
||||
int type = 0; /* block header */
|
||||
last = sinfl_get(&in,e,&s,1);
|
||||
type = sinfl_get(&in,e,&s,2);
|
||||
/* block header */
|
||||
int type = 0;
|
||||
sinfl_refill(&s);
|
||||
last = sinfl__get(&s,1);
|
||||
type = sinfl__get(&s,2);
|
||||
|
||||
switch (type) {default: return (int)(out-o);
|
||||
case 0x00: state = stored; break;
|
||||
|
@ -322,10 +401,12 @@ sinfl_decompress(unsigned char *out, const unsigned char *in, int size) {
|
|||
case 0x02: state = dyn; break;}
|
||||
} break;
|
||||
case stored: {
|
||||
int len; /* uncompressed block */
|
||||
sinfl_get(&in,e,&s,s.bitcnt & 7);
|
||||
len = sinfl_get(&in,e,&s,16);
|
||||
//int nlen = sinfl_get(&in,e,&s,16);
|
||||
/* uncompressed block */
|
||||
int len;
|
||||
sinfl_refill(&s);
|
||||
sinfl__get(&s,s.bitcnt & 7);
|
||||
len = sinfl__get(&s,16);
|
||||
//int nlen = sinfl__get(&s,16); // @raysan5: Unused variable?
|
||||
in -= 2; s.bitcnt = 0;
|
||||
|
||||
if (len > (e-in) || !len)
|
||||
|
@ -353,72 +434,111 @@ sinfl_decompress(unsigned char *out, const unsigned char *in, int size) {
|
|||
int n, i;
|
||||
unsigned hlens[SINFL_PRE_TBL_SIZE];
|
||||
unsigned char nlens[19] = {0}, lens[288+32];
|
||||
int nlit = 257 + sinfl_get(&in,e,&s,5);
|
||||
int ndist = 1 + sinfl_get(&in,e,&s,5);
|
||||
int nlen = 4 + sinfl_get(&in,e,&s,4);
|
||||
|
||||
sinfl_refill(&s);
|
||||
{int nlit = 257 + sinfl__get(&s,5);
|
||||
int ndist = 1 + sinfl__get(&s,5);
|
||||
int nlen = 4 + sinfl__get(&s,4);
|
||||
for (n = 0; n < nlen; n++)
|
||||
nlens[order[n]] = (unsigned char)sinfl_get(&in,e,&s,3);
|
||||
nlens[order[n]] = (unsigned char)sinfl_get(&s,3);
|
||||
sinfl_build(hlens, nlens, 7, 7, 19);
|
||||
|
||||
/* decode code lengths */
|
||||
for (n = 0; n < nlit + ndist;) {
|
||||
int sym = sinfl_decode(&in, e, &s, hlens, 7);
|
||||
int sym = sinfl_decode(&s, hlens, 7);
|
||||
switch (sym) {default: lens[n++] = (unsigned char)sym; break;
|
||||
case 16: for (i=3+sinfl_get(&in,e,&s,2);i;i--,n++) lens[n]=lens[n-1]; break;
|
||||
case 17: for (i=3+sinfl_get(&in,e,&s,3);i;i--,n++) lens[n]=0; break;
|
||||
case 18: for (i=11+sinfl_get(&in,e,&s,7);i;i--,n++) lens[n]=0; break;}
|
||||
case 16: for (i=3+sinfl_get(&s,2);i;i--,n++) lens[n]=lens[n-1]; break;
|
||||
case 17: for (i=3+sinfl_get(&s,3);i;i--,n++) lens[n]=0; break;
|
||||
case 18: for (i=11+sinfl_get(&s,7);i;i--,n++) lens[n]=0; break;}
|
||||
}
|
||||
/* build lit/dist tables */
|
||||
sinfl_build(s.lits, lens, 10, 15, nlit);
|
||||
sinfl_build(s.dsts, lens + nlit, 8, 15, ndist);
|
||||
state = blk;
|
||||
state = blk;}
|
||||
} break;
|
||||
case blk: {
|
||||
/* decompress block */
|
||||
int i, sym = sinfl_decode(&in, e, &s, s.lits, 10);
|
||||
if (sym > 256) {sym -= 257; /* match symbol */
|
||||
{int len = sinfl_get(&in, e, &s, lbits[sym]) + lbase[sym];
|
||||
int dsym = sinfl_decode(&in, e, &s, s.dsts, 8);
|
||||
int offs = sinfl_get(&in, e, &s, dbits[dsym]) + dbase[dsym];
|
||||
if (offs > (int)(out-o)) {
|
||||
int sym = sinfl_decode(&s, s.lits, 10);
|
||||
if (sym < 256) {
|
||||
/* literal */
|
||||
*out++ = (unsigned char)sym;
|
||||
} else if (sym > 256) {sym -= 257; /* match symbol */
|
||||
sinfl_refill(&s);
|
||||
{int len = sinfl__get(&s, lbits[sym]) + lbase[sym];
|
||||
int dsym = sinfl_decode(&s, s.dsts, 8);
|
||||
int offs = sinfl__get(&s, dbits[dsym]) + dbase[dsym];
|
||||
unsigned char *dst = out, *src = out - offs;
|
||||
if (sinfl_unlikely(offs > (int)(out-o))) {
|
||||
return (int)(out-o);
|
||||
}
|
||||
out = out + len;
|
||||
|
||||
#ifndef SINFL_NO_SIMD
|
||||
if (sinfl_likely(oe - out >= 16 * 3)) {
|
||||
if (offs >= 16) {
|
||||
/* copy match */
|
||||
sinfl_copy128(&dst, &src);
|
||||
sinfl_copy128(&dst, &src);
|
||||
do sinfl_copy128(&dst, &src);
|
||||
while (dst < out);
|
||||
} else if (offs == 1) {
|
||||
/* rle match copying */
|
||||
unsigned char c = *(out - offs);
|
||||
unsigned long w = (c << 24) | (c << 16) | (c << 8) | c;
|
||||
for (i = 0; i < len >> 2; ++i) {
|
||||
memcpy(out, &w, 4);
|
||||
out += 4;
|
||||
sinfl_char16 w = sinfl_char16_char(src[0]);
|
||||
dst = sinfl_write128(dst, w);
|
||||
dst = sinfl_write128(dst, w);
|
||||
do dst = sinfl_write128(dst, w);
|
||||
while (dst < out);
|
||||
} else {
|
||||
*dst++ = *src++;
|
||||
*dst++ = *src++;
|
||||
do *dst++ = *src++;
|
||||
while (dst < out);
|
||||
}
|
||||
len = len & 3;
|
||||
} else if (offs >= 4) {
|
||||
}
|
||||
#else
|
||||
if (sinfl_likely(oe - out >= 3 * 8 - 3)) {
|
||||
if (offs >= 8) {
|
||||
/* copy match */
|
||||
int wcnt = len >> 2;
|
||||
for (i = 0; i < wcnt; ++i) {
|
||||
unsigned long w = 0;
|
||||
memcpy(&w, out - offs, 4);
|
||||
memcpy(out, &w, 4);
|
||||
out += 4;
|
||||
sinfl_copy64(&dst, &src);
|
||||
sinfl_copy64(&dst, &src);
|
||||
do sinfl_copy64(&dst, &src);
|
||||
while (dst < out);
|
||||
} else if (offs == 1) {
|
||||
/* rle match copying */
|
||||
unsigned int c = src[0];
|
||||
unsigned int hw = (c << 24u) | (c << 16u) | (c << 8u) | (unsigned)c;
|
||||
unsigned long long w = (unsigned long long)hw << 32llu | hw;
|
||||
dst = sinfl_write64(dst, w);
|
||||
dst = sinfl_write64(dst, w);
|
||||
do dst = sinfl_write64(dst, w);
|
||||
while (dst < out);
|
||||
} else {
|
||||
*dst++ = *src++;
|
||||
*dst++ = *src++;
|
||||
do *dst++ = *src++;
|
||||
while (dst < out);
|
||||
}
|
||||
len = len & 3;
|
||||
}
|
||||
for (i = 0; i < len; ++i)
|
||||
{*out = *(out-offs), out++;}
|
||||
#endif
|
||||
else {
|
||||
*dst++ = *src++;
|
||||
*dst++ = *src++;
|
||||
do *dst++ = *src++;
|
||||
while (dst < out);}
|
||||
}
|
||||
} else if (sym == 256) {
|
||||
} else {
|
||||
/* end of block */
|
||||
if (last) return (int)(out-o);
|
||||
state = hdr;
|
||||
break;
|
||||
/* literal */
|
||||
} else *out++ = (unsigned char)sym;
|
||||
}
|
||||
} break;}
|
||||
}
|
||||
return (int)(out-o);
|
||||
}
|
||||
extern int
|
||||
sinflate(void *out, const void *in, int size) {
|
||||
return sinfl_decompress((unsigned char*)out, (const unsigned char*)in, size);
|
||||
sinflate(void *out, int cap, const void *in, int size) {
|
||||
return sinfl_decompress((unsigned char*)out, cap, (const unsigned char*)in, size);
|
||||
}
|
||||
static unsigned
|
||||
sinfl_adler32(unsigned adler32, const unsigned char *in, int in_len) {
|
||||
|
@ -448,11 +568,11 @@ sinfl_adler32(unsigned adler32, const unsigned char *in, int in_len) {
|
|||
} return (unsigned)(s2 << 16) + (unsigned)s1;
|
||||
}
|
||||
extern int
|
||||
zsinflate(void *out, const void *mem, int size) {
|
||||
zsinflate(void *out, int cap, const void *mem, int size) {
|
||||
const unsigned char *in = (const unsigned char*)mem;
|
||||
if (size >= 6) {
|
||||
const unsigned char *eob = in + size - 4;
|
||||
int n = sinfl_decompress((unsigned char*)out, in + 2u, size);
|
||||
int n = sinfl_decompress((unsigned char*)out, cap, in + 2u, size);
|
||||
unsigned a = sinfl_adler32(1u, (unsigned char*)out, n);
|
||||
unsigned h = eob[0] << 24 | eob[1] << 16 | eob[2] << 8 | eob[3] << 0;
|
||||
return a == h ? n : -1;
|
||||
|
|
277
raylib/external/stb_image.h
vendored
277
raylib/external/stb_image.h
vendored
|
@ -1,4 +1,4 @@
|
|||
/* stb_image - v2.26 - public domain image loader - http://nothings.org/stb
|
||||
/* stb_image - v2.27 - public domain image loader - http://nothings.org/stb
|
||||
no warranty implied; use at your own risk
|
||||
|
||||
Do this:
|
||||
|
@ -48,6 +48,7 @@ LICENSE
|
|||
|
||||
RECENT REVISION HISTORY:
|
||||
|
||||
2.27 (2021-07-11) document stbi_info better, 16-bit PNM support, bug fixes
|
||||
2.26 (2020-07-13) many minor fixes
|
||||
2.25 (2020-02-02) fix warnings
|
||||
2.24 (2020-02-02) fix warnings; thread-local failure_reason and flip_vertically
|
||||
|
@ -89,7 +90,7 @@ RECENT REVISION HISTORY:
|
|||
Jeremy Sawicki (handle all ImageNet JPGs)
|
||||
Optimizations & bugfixes Mikhail Morozov (1-bit BMP)
|
||||
Fabian "ryg" Giesen Anael Seghezzi (is-16-bit query)
|
||||
Arseny Kapoulkine
|
||||
Arseny Kapoulkine Simon Breuss (16-bit PNM)
|
||||
John-Mark Allen
|
||||
Carmelo J Fdez-Aguera
|
||||
|
||||
|
@ -102,7 +103,7 @@ RECENT REVISION HISTORY:
|
|||
Thomas Ruf Ronny Chevalier github:rlyeh
|
||||
Janez Zemva John Bartholomew Michal Cichon github:romigrou
|
||||
Jonathan Blow Ken Hamada Tero Hanninen github:svdijk
|
||||
Laurent Gomila Cort Stratton github:snagar
|
||||
Eugene Golushkov Laurent Gomila Cort Stratton github:snagar
|
||||
Aruelien Pocheville Sergio Gonzalez Thibault Reuille github:Zelex
|
||||
Cass Everitt Ryamond Barbiero github:grim210
|
||||
Paul Du Bois Engin Manap Aldo Culquicondor github:sammyhw
|
||||
|
@ -110,11 +111,13 @@ RECENT REVISION HISTORY:
|
|||
Josh Tobin Matthew Gregan github:poppolopoppo
|
||||
Julian Raschke Gregory Mullen Christian Floisand github:darealshinji
|
||||
Baldur Karlsson Kevin Schmidt JR Smith github:Michaelangel007
|
||||
Brad Weinberger Matvey Cherevko [reserved]
|
||||
Brad Weinberger Matvey Cherevko github:mosra
|
||||
Luca Sas Alexander Veselov Zack Middleton [reserved]
|
||||
Ryan C. Gordon [reserved] [reserved]
|
||||
DO NOT ADD YOUR NAME HERE
|
||||
|
||||
Jacko Dirks
|
||||
|
||||
To add your name to the credits, pick a random blank space in the middle and fill it.
|
||||
80% of merge conflicts on stb PRs are due to people adding their name at the end
|
||||
of the credits.
|
||||
|
@ -176,6 +179,32 @@ RECENT REVISION HISTORY:
|
|||
//
|
||||
// Paletted PNG, BMP, GIF, and PIC images are automatically depalettized.
|
||||
//
|
||||
// To query the width, height and component count of an image without having to
|
||||
// decode the full file, you can use the stbi_info family of functions:
|
||||
//
|
||||
// int x,y,n,ok;
|
||||
// ok = stbi_info(filename, &x, &y, &n);
|
||||
// // returns ok=1 and sets x, y, n if image is a supported format,
|
||||
// // 0 otherwise.
|
||||
//
|
||||
// Note that stb_image pervasively uses ints in its public API for sizes,
|
||||
// including sizes of memory buffers. This is now part of the API and thus
|
||||
// hard to change without causing breakage. As a result, the various image
|
||||
// loaders all have certain limits on image size; these differ somewhat
|
||||
// by format but generally boil down to either just under 2GB or just under
|
||||
// 1GB. When the decoded image would be larger than this, stb_image decoding
|
||||
// will fail.
|
||||
//
|
||||
// Additionally, stb_image will reject image files that have any of their
|
||||
// dimensions set to a larger value than the configurable STBI_MAX_DIMENSIONS,
|
||||
// which defaults to 2**24 = 16777216 pixels. Due to the above memory limit,
|
||||
// the only way to have an image with such dimensions load correctly
|
||||
// is for it to have a rather extreme aspect ratio. Either way, the
|
||||
// assumption here is that such larger images are likely to be malformed
|
||||
// or malicious. If you do need to load an image with individual dimensions
|
||||
// larger than that, and it still fits in the overall size limit, you can
|
||||
// #define STBI_MAX_DIMENSIONS on your own to be something larger.
|
||||
//
|
||||
// ===========================================================================
|
||||
//
|
||||
// UNICODE:
|
||||
|
@ -281,11 +310,10 @@ RECENT REVISION HISTORY:
|
|||
//
|
||||
// iPhone PNG support:
|
||||
//
|
||||
// By default we convert iphone-formatted PNGs back to RGB, even though
|
||||
// they are internally encoded differently. You can disable this conversion
|
||||
// by calling stbi_convert_iphone_png_to_rgb(0), in which case
|
||||
// you will always just get the native iphone "format" through (which
|
||||
// is BGR stored in RGB).
|
||||
// We optionally support converting iPhone-formatted PNGs (which store
|
||||
// premultiplied BGRA) back to RGB, even though they're internally encoded
|
||||
// differently. To enable this conversion, call
|
||||
// stbi_convert_iphone_png_to_rgb(1).
|
||||
//
|
||||
// Call stbi_set_unpremultiply_on_load(1) as well to force a divide per
|
||||
// pixel to remove any premultiplied alpha *only* if the image file explicitly
|
||||
|
@ -489,6 +517,8 @@ STBIDEF void stbi_set_flip_vertically_on_load(int flag_true_if_should_flip);
|
|||
// as above, but only applies to images loaded on the thread that calls the function
|
||||
// this function is only available if your compiler supports thread-local variables;
|
||||
// calling it will fail to link if your compiler doesn't
|
||||
STBIDEF void stbi_set_unpremultiply_on_load_thread(int flag_true_if_should_unpremultiply);
|
||||
STBIDEF void stbi_convert_iphone_png_to_rgb_thread(int flag_true_if_should_convert);
|
||||
STBIDEF void stbi_set_flip_vertically_on_load_thread(int flag_true_if_should_flip);
|
||||
|
||||
// ZLIB client - used by PNG, available for other purposes
|
||||
|
@ -634,7 +664,7 @@ typedef unsigned char validate_uint32[sizeof(stbi__uint32)==4 ? 1 : -1];
|
|||
#ifdef STBI_HAS_LROTL
|
||||
#define stbi_lrot(x,y) _lrotl(x,y)
|
||||
#else
|
||||
#define stbi_lrot(x,y) (((x) << (y)) | ((x) >> (32 - (y))))
|
||||
#define stbi_lrot(x,y) (((x) << (y)) | ((x) >> (-(y) & 31)))
|
||||
#endif
|
||||
|
||||
#if defined(STBI_MALLOC) && defined(STBI_FREE) && (defined(STBI_REALLOC) || defined(STBI_REALLOC_SIZED))
|
||||
|
@ -748,9 +778,12 @@ static int stbi__sse2_available(void)
|
|||
|
||||
#ifdef STBI_NEON
|
||||
#include <arm_neon.h>
|
||||
// assume GCC or Clang on ARM targets
|
||||
#ifdef _MSC_VER
|
||||
#define STBI_SIMD_ALIGN(type, name) __declspec(align(16)) type name
|
||||
#else
|
||||
#define STBI_SIMD_ALIGN(type, name) type name __attribute__((aligned(16)))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef STBI_SIMD_ALIGN
|
||||
#define STBI_SIMD_ALIGN(type, name) type name
|
||||
|
@ -924,6 +957,7 @@ static int stbi__gif_info(stbi__context *s, int *x, int *y, int *comp);
|
|||
static int stbi__pnm_test(stbi__context *s);
|
||||
static void *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req_comp, stbi__result_info *ri);
|
||||
static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp);
|
||||
static int stbi__pnm_is16(stbi__context *s);
|
||||
#endif
|
||||
|
||||
static
|
||||
|
@ -998,7 +1032,7 @@ static int stbi__mad3sizes_valid(int a, int b, int c, int add)
|
|||
}
|
||||
|
||||
// returns 1 if "a*b*c*d + add" has no negative terms/factors and doesn't overflow
|
||||
#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR)
|
||||
#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) || !defined(STBI_NO_PNM)
|
||||
static int stbi__mad4sizes_valid(int a, int b, int c, int d, int add)
|
||||
{
|
||||
return stbi__mul2sizes_valid(a, b) && stbi__mul2sizes_valid(a*b, c) &&
|
||||
|
@ -1021,7 +1055,7 @@ static void *stbi__malloc_mad3(int a, int b, int c, int add)
|
|||
return stbi__malloc(a*b*c + add);
|
||||
}
|
||||
|
||||
#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR)
|
||||
#if !defined(STBI_NO_LINEAR) || !defined(STBI_NO_HDR) || !defined(STBI_NO_PNM)
|
||||
static void *stbi__malloc_mad4(int a, int b, int c, int d, int add)
|
||||
{
|
||||
if (!stbi__mad4sizes_valid(a, b, c, d, add)) return NULL;
|
||||
|
@ -1087,9 +1121,8 @@ static void *stbi__load_main(stbi__context *s, int *x, int *y, int *comp, int re
|
|||
ri->channel_order = STBI_ORDER_RGB; // all current input & output are this, but this is here so we can add BGR order
|
||||
ri->num_channels = 0;
|
||||
|
||||
#ifndef STBI_NO_JPEG
|
||||
if (stbi__jpeg_test(s)) return stbi__jpeg_load(s,x,y,comp,req_comp, ri);
|
||||
#endif
|
||||
// test the formats with a very explicit header first (at least a FOURCC
|
||||
// or distinctive magic number first)
|
||||
#ifndef STBI_NO_PNG
|
||||
if (stbi__png_test(s)) return stbi__png_load(s,x,y,comp,req_comp, ri);
|
||||
#endif
|
||||
|
@ -1107,6 +1140,13 @@ static void *stbi__load_main(stbi__context *s, int *x, int *y, int *comp, int re
|
|||
#ifndef STBI_NO_PIC
|
||||
if (stbi__pic_test(s)) return stbi__pic_load(s,x,y,comp,req_comp, ri);
|
||||
#endif
|
||||
|
||||
// then the formats that can end up attempting to load with just 1 or 2
|
||||
// bytes matching expectations; these are prone to false positives, so
|
||||
// try them later
|
||||
#ifndef STBI_NO_JPEG
|
||||
if (stbi__jpeg_test(s)) return stbi__jpeg_load(s,x,y,comp,req_comp, ri);
|
||||
#endif
|
||||
#ifndef STBI_NO_PNM
|
||||
if (stbi__pnm_test(s)) return stbi__pnm_load(s,x,y,comp,req_comp, ri);
|
||||
#endif
|
||||
|
@ -1262,12 +1302,12 @@ static void stbi__float_postprocess(float *result, int *x, int *y, int *comp, in
|
|||
|
||||
#ifndef STBI_NO_STDIO
|
||||
|
||||
#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)
|
||||
#if defined(_WIN32) && defined(STBI_WINDOWS_UTF8)
|
||||
STBI_EXTERN __declspec(dllimport) int __stdcall MultiByteToWideChar(unsigned int cp, unsigned long flags, const char *str, int cbmb, wchar_t *widestr, int cchwide);
|
||||
STBI_EXTERN __declspec(dllimport) int __stdcall WideCharToMultiByte(unsigned int cp, unsigned long flags, const wchar_t *widestr, int cchwide, char *str, int cbmb, const char *defchar, int *used_default);
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)
|
||||
#if defined(_WIN32) && defined(STBI_WINDOWS_UTF8)
|
||||
STBIDEF int stbi_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input)
|
||||
{
|
||||
return WideCharToMultiByte(65001 /* UTF8 */, 0, input, -1, buffer, (int) bufferlen, NULL, NULL);
|
||||
|
@ -1277,16 +1317,16 @@ STBIDEF int stbi_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wch
|
|||
static FILE *stbi__fopen(char const *filename, char const *mode)
|
||||
{
|
||||
FILE *f;
|
||||
#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)
|
||||
#if defined(_WIN32) && defined(STBI_WINDOWS_UTF8)
|
||||
wchar_t wMode[64];
|
||||
wchar_t wFilename[1024];
|
||||
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, filename, -1, wFilename, sizeof(wFilename)))
|
||||
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, filename, -1, wFilename, sizeof(wFilename)/sizeof(*wFilename)))
|
||||
return 0;
|
||||
|
||||
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, mode, -1, wMode, sizeof(wMode)))
|
||||
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, mode, -1, wMode, sizeof(wMode)/sizeof(*wMode)))
|
||||
return 0;
|
||||
|
||||
#if _MSC_VER >= 1400
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||
if (0 != _wfopen_s(&f, wFilename, wMode))
|
||||
f = 0;
|
||||
#else
|
||||
|
@ -1662,7 +1702,8 @@ static int stbi__get16le(stbi__context *s)
|
|||
static stbi__uint32 stbi__get32le(stbi__context *s)
|
||||
{
|
||||
stbi__uint32 z = stbi__get16le(s);
|
||||
return z + (stbi__get16le(s) << 16);
|
||||
z += (stbi__uint32)stbi__get16le(s) << 16;
|
||||
return z;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -2090,13 +2131,12 @@ stbi_inline static int stbi__extend_receive(stbi__jpeg *j, int n)
|
|||
int sgn;
|
||||
if (j->code_bits < n) stbi__grow_buffer_unsafe(j);
|
||||
|
||||
sgn = (stbi__int32)j->code_buffer >> 31; // sign bit is always in MSB
|
||||
sgn = j->code_buffer >> 31; // sign bit always in MSB; 0 if MSB clear (positive), 1 if MSB set (negative)
|
||||
k = stbi_lrot(j->code_buffer, n);
|
||||
if (n < 0 || n >= (int) (sizeof(stbi__bmask)/sizeof(*stbi__bmask))) return 0;
|
||||
j->code_buffer = k & ~stbi__bmask[n];
|
||||
k &= stbi__bmask[n];
|
||||
j->code_bits -= n;
|
||||
return k + (stbi__jbias[n] & ~sgn);
|
||||
return k + (stbi__jbias[n] & (sgn - 1));
|
||||
}
|
||||
|
||||
// get some unsigned bits
|
||||
|
@ -2146,7 +2186,7 @@ static int stbi__jpeg_decode_block(stbi__jpeg *j, short data[64], stbi__huffman
|
|||
|
||||
if (j->code_bits < 16) stbi__grow_buffer_unsafe(j);
|
||||
t = stbi__jpeg_huff_decode(j, hdc);
|
||||
if (t < 0) return stbi__err("bad huffman code","Corrupt JPEG");
|
||||
if (t < 0 || t > 15) return stbi__err("bad huffman code","Corrupt JPEG");
|
||||
|
||||
// 0 all the ac values now so we can do it 32-bits at a time
|
||||
memset(data,0,64*sizeof(data[0]));
|
||||
|
@ -2203,12 +2243,12 @@ static int stbi__jpeg_decode_block_prog_dc(stbi__jpeg *j, short data[64], stbi__
|
|||
// first scan for DC coefficient, must be first
|
||||
memset(data,0,64*sizeof(data[0])); // 0 all the ac values now
|
||||
t = stbi__jpeg_huff_decode(j, hdc);
|
||||
if (t == -1) return stbi__err("can't merge dc and ac", "Corrupt JPEG");
|
||||
if (t < 0 || t > 15) return stbi__err("can't merge dc and ac", "Corrupt JPEG");
|
||||
diff = t ? stbi__extend_receive(j, t) : 0;
|
||||
|
||||
dc = j->img_comp[b].dc_pred + diff;
|
||||
j->img_comp[b].dc_pred = dc;
|
||||
data[0] = (short) (dc << j->succ_low);
|
||||
data[0] = (short) (dc * (1 << j->succ_low));
|
||||
} else {
|
||||
// refinement scan for DC coefficient
|
||||
if (stbi__jpeg_get_bit(j))
|
||||
|
@ -2245,7 +2285,7 @@ static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg *j, short data[64], stbi__
|
|||
j->code_buffer <<= s;
|
||||
j->code_bits -= s;
|
||||
zig = stbi__jpeg_dezigzag[k++];
|
||||
data[zig] = (short) ((r >> 8) << shift);
|
||||
data[zig] = (short) ((r >> 8) * (1 << shift));
|
||||
} else {
|
||||
int rs = stbi__jpeg_huff_decode(j, hac);
|
||||
if (rs < 0) return stbi__err("bad huffman code","Corrupt JPEG");
|
||||
|
@ -2263,7 +2303,7 @@ static int stbi__jpeg_decode_block_prog_ac(stbi__jpeg *j, short data[64], stbi__
|
|||
} else {
|
||||
k += r;
|
||||
zig = stbi__jpeg_dezigzag[k++];
|
||||
data[zig] = (short) (stbi__extend_receive(j,s) << shift);
|
||||
data[zig] = (short) (stbi__extend_receive(j,s) * (1 << shift));
|
||||
}
|
||||
}
|
||||
} while (k <= j->spec_end);
|
||||
|
@ -3227,6 +3267,13 @@ static int stbi__process_frame_header(stbi__jpeg *z, int scan)
|
|||
if (z->img_comp[i].v > v_max) v_max = z->img_comp[i].v;
|
||||
}
|
||||
|
||||
// check that plane subsampling factors are integer ratios; our resamplers can't deal with fractional ratios
|
||||
// and I've never seen a non-corrupted JPEG file actually use them
|
||||
for (i=0; i < s->img_n; ++i) {
|
||||
if (h_max % z->img_comp[i].h != 0) return stbi__err("bad H","Corrupt JPEG");
|
||||
if (v_max % z->img_comp[i].v != 0) return stbi__err("bad V","Corrupt JPEG");
|
||||
}
|
||||
|
||||
// compute interleaved mcu info
|
||||
z->img_h_max = h_max;
|
||||
z->img_v_max = v_max;
|
||||
|
@ -3782,6 +3829,10 @@ static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp
|
|||
else
|
||||
decode_n = z->s->img_n;
|
||||
|
||||
// nothing to do if no components requested; check this now to avoid
|
||||
// accessing uninitialized coutput[0] later
|
||||
if (decode_n <= 0) { stbi__cleanup_jpeg(z); return NULL; }
|
||||
|
||||
// resample and color-convert
|
||||
{
|
||||
int k;
|
||||
|
@ -3924,6 +3975,7 @@ static void *stbi__jpeg_load(stbi__context *s, int *x, int *y, int *comp, int re
|
|||
{
|
||||
unsigned char* result;
|
||||
stbi__jpeg* j = (stbi__jpeg*) stbi__malloc(sizeof(stbi__jpeg));
|
||||
if (!j) return stbi__errpuc("outofmem", "Out of memory");
|
||||
STBI_NOTUSED(ri);
|
||||
j->s = s;
|
||||
stbi__setup_jpeg(j);
|
||||
|
@ -3936,6 +3988,7 @@ static int stbi__jpeg_test(stbi__context *s)
|
|||
{
|
||||
int r;
|
||||
stbi__jpeg* j = (stbi__jpeg*)stbi__malloc(sizeof(stbi__jpeg));
|
||||
if (!j) return stbi__err("outofmem", "Out of memory");
|
||||
j->s = s;
|
||||
stbi__setup_jpeg(j);
|
||||
r = stbi__decode_jpeg_header(j, STBI__SCAN_type);
|
||||
|
@ -3960,6 +4013,7 @@ static int stbi__jpeg_info(stbi__context *s, int *x, int *y, int *comp)
|
|||
{
|
||||
int result;
|
||||
stbi__jpeg* j = (stbi__jpeg*) (stbi__malloc(sizeof(stbi__jpeg)));
|
||||
if (!j) return stbi__err("outofmem", "Out of memory");
|
||||
j->s = s;
|
||||
result = stbi__jpeg_info_raw(j, x, y, comp);
|
||||
STBI_FREE(j);
|
||||
|
@ -3979,6 +4033,7 @@ static int stbi__jpeg_info(stbi__context *s, int *x, int *y, int *comp)
|
|||
// fast-way is faster to check than jpeg huffman, but slow way is slower
|
||||
#define STBI__ZFAST_BITS 9 // accelerate all cases in default tables
|
||||
#define STBI__ZFAST_MASK ((1 << STBI__ZFAST_BITS) - 1)
|
||||
#define STBI__ZNSYMS 288 // number of symbols in literal/length alphabet
|
||||
|
||||
// zlib-style huffman encoding
|
||||
// (jpegs packs from left, zlib from right, so can't share code)
|
||||
|
@ -3988,8 +4043,8 @@ typedef struct
|
|||
stbi__uint16 firstcode[16];
|
||||
int maxcode[17];
|
||||
stbi__uint16 firstsymbol[16];
|
||||
stbi_uc size[288];
|
||||
stbi__uint16 value[288];
|
||||
stbi_uc size[STBI__ZNSYMS];
|
||||
stbi__uint16 value[STBI__ZNSYMS];
|
||||
} stbi__zhuffman;
|
||||
|
||||
stbi_inline static int stbi__bitreverse16(int n)
|
||||
|
@ -4120,7 +4175,7 @@ static int stbi__zhuffman_decode_slowpath(stbi__zbuf *a, stbi__zhuffman *z)
|
|||
if (s >= 16) return -1; // invalid code!
|
||||
// code size is s, so:
|
||||
b = (k >> (16-s)) - z->firstcode[s] + z->firstsymbol[s];
|
||||
if (b >= sizeof (z->size)) return -1; // some data was corrupt somewhere!
|
||||
if (b >= STBI__ZNSYMS) return -1; // some data was corrupt somewhere!
|
||||
if (z->size[b] != s) return -1; // was originally an assert, but report failure instead.
|
||||
a->code_buffer >>= s;
|
||||
a->num_bits -= s;
|
||||
|
@ -4317,7 +4372,7 @@ static int stbi__parse_zlib_header(stbi__zbuf *a)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static const stbi_uc stbi__zdefault_length[288] =
|
||||
static const stbi_uc stbi__zdefault_length[STBI__ZNSYMS] =
|
||||
{
|
||||
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
|
||||
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
|
||||
|
@ -4363,7 +4418,7 @@ static int stbi__parse_zlib(stbi__zbuf *a, int parse_header)
|
|||
} else {
|
||||
if (type == 1) {
|
||||
// use fixed code lengths
|
||||
if (!stbi__zbuild_huffman(&a->z_length , stbi__zdefault_length , 288)) return 0;
|
||||
if (!stbi__zbuild_huffman(&a->z_length , stbi__zdefault_length , STBI__ZNSYMS)) return 0;
|
||||
if (!stbi__zbuild_huffman(&a->z_distance, stbi__zdefault_distance, 32)) return 0;
|
||||
} else {
|
||||
if (!stbi__compute_huffman_codes(a)) return 0;
|
||||
|
@ -4759,6 +4814,7 @@ static int stbi__create_png_image(stbi__png *a, stbi_uc *image_data, stbi__uint3
|
|||
|
||||
// de-interlacing
|
||||
final = (stbi_uc *) stbi__malloc_mad3(a->s->img_x, a->s->img_y, out_bytes, 0);
|
||||
if (!final) return stbi__err("outofmem", "Out of memory");
|
||||
for (p=0; p < 7; ++p) {
|
||||
int xorig[] = { 0,4,0,2,0,1,0 };
|
||||
int yorig[] = { 0,0,4,0,2,0,1 };
|
||||
|
@ -4879,19 +4935,46 @@ static int stbi__expand_png_palette(stbi__png *a, stbi_uc *palette, int len, int
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int stbi__unpremultiply_on_load = 0;
|
||||
static int stbi__de_iphone_flag = 0;
|
||||
static int stbi__unpremultiply_on_load_global = 0;
|
||||
static int stbi__de_iphone_flag_global = 0;
|
||||
|
||||
STBIDEF void stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply)
|
||||
{
|
||||
stbi__unpremultiply_on_load = flag_true_if_should_unpremultiply;
|
||||
stbi__unpremultiply_on_load_global = flag_true_if_should_unpremultiply;
|
||||
}
|
||||
|
||||
STBIDEF void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert)
|
||||
{
|
||||
stbi__de_iphone_flag = flag_true_if_should_convert;
|
||||
stbi__de_iphone_flag_global = flag_true_if_should_convert;
|
||||
}
|
||||
|
||||
#ifndef STBI_THREAD_LOCAL
|
||||
#define stbi__unpremultiply_on_load stbi__unpremultiply_on_load_global
|
||||
#define stbi__de_iphone_flag stbi__de_iphone_flag_global
|
||||
#else
|
||||
static STBI_THREAD_LOCAL int stbi__unpremultiply_on_load_local, stbi__unpremultiply_on_load_set;
|
||||
static STBI_THREAD_LOCAL int stbi__de_iphone_flag_local, stbi__de_iphone_flag_set;
|
||||
|
||||
STBIDEF void stbi__unpremultiply_on_load_thread(int flag_true_if_should_unpremultiply)
|
||||
{
|
||||
stbi__unpremultiply_on_load_local = flag_true_if_should_unpremultiply;
|
||||
stbi__unpremultiply_on_load_set = 1;
|
||||
}
|
||||
|
||||
STBIDEF void stbi_convert_iphone_png_to_rgb_thread(int flag_true_if_should_convert)
|
||||
{
|
||||
stbi__de_iphone_flag_local = flag_true_if_should_convert;
|
||||
stbi__de_iphone_flag_set = 1;
|
||||
}
|
||||
|
||||
#define stbi__unpremultiply_on_load (stbi__unpremultiply_on_load_set \
|
||||
? stbi__unpremultiply_on_load_local \
|
||||
: stbi__unpremultiply_on_load_global)
|
||||
#define stbi__de_iphone_flag (stbi__de_iphone_flag_set \
|
||||
? stbi__de_iphone_flag_local \
|
||||
: stbi__de_iphone_flag_global)
|
||||
#endif // STBI_THREAD_LOCAL
|
||||
|
||||
static void stbi__de_iphone(stbi__png *z)
|
||||
{
|
||||
stbi__context *s = z->s;
|
||||
|
@ -5272,6 +5355,32 @@ typedef struct
|
|||
int extra_read;
|
||||
} stbi__bmp_data;
|
||||
|
||||
static int stbi__bmp_set_mask_defaults(stbi__bmp_data *info, int compress)
|
||||
{
|
||||
// BI_BITFIELDS specifies masks explicitly, don't override
|
||||
if (compress == 3)
|
||||
return 1;
|
||||
|
||||
if (compress == 0) {
|
||||
if (info->bpp == 16) {
|
||||
info->mr = 31u << 10;
|
||||
info->mg = 31u << 5;
|
||||
info->mb = 31u << 0;
|
||||
} else if (info->bpp == 32) {
|
||||
info->mr = 0xffu << 16;
|
||||
info->mg = 0xffu << 8;
|
||||
info->mb = 0xffu << 0;
|
||||
info->ma = 0xffu << 24;
|
||||
info->all_a = 0; // if all_a is 0 at end, then we loaded alpha channel but it was all 0
|
||||
} else {
|
||||
// otherwise, use defaults, which is all-0
|
||||
info->mr = info->mg = info->mb = info->ma = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0; // error
|
||||
}
|
||||
|
||||
static void *stbi__bmp_parse_header(stbi__context *s, stbi__bmp_data *info)
|
||||
{
|
||||
int hsz;
|
||||
|
@ -5299,6 +5408,8 @@ static void *stbi__bmp_parse_header(stbi__context *s, stbi__bmp_data *info)
|
|||
if (hsz != 12) {
|
||||
int compress = stbi__get32le(s);
|
||||
if (compress == 1 || compress == 2) return stbi__errpuc("BMP RLE", "BMP type not supported: RLE");
|
||||
if (compress >= 4) return stbi__errpuc("BMP JPEG/PNG", "BMP type not supported: unsupported compression"); // this includes PNG/JPEG modes
|
||||
if (compress == 3 && info->bpp != 16 && info->bpp != 32) return stbi__errpuc("bad BMP", "bad BMP"); // bitfields requires 16 or 32 bits/pixel
|
||||
stbi__get32le(s); // discard sizeof
|
||||
stbi__get32le(s); // discard hres
|
||||
stbi__get32le(s); // discard vres
|
||||
|
@ -5313,17 +5424,7 @@ static void *stbi__bmp_parse_header(stbi__context *s, stbi__bmp_data *info)
|
|||
}
|
||||
if (info->bpp == 16 || info->bpp == 32) {
|
||||
if (compress == 0) {
|
||||
if (info->bpp == 32) {
|
||||
info->mr = 0xffu << 16;
|
||||
info->mg = 0xffu << 8;
|
||||
info->mb = 0xffu << 0;
|
||||
info->ma = 0xffu << 24;
|
||||
info->all_a = 0; // if all_a is 0 at end, then we loaded alpha channel but it was all 0
|
||||
} else {
|
||||
info->mr = 31u << 10;
|
||||
info->mg = 31u << 5;
|
||||
info->mb = 31u << 0;
|
||||
}
|
||||
stbi__bmp_set_mask_defaults(info, compress);
|
||||
} else if (compress == 3) {
|
||||
info->mr = stbi__get32le(s);
|
||||
info->mg = stbi__get32le(s);
|
||||
|
@ -5338,6 +5439,7 @@ static void *stbi__bmp_parse_header(stbi__context *s, stbi__bmp_data *info)
|
|||
return stbi__errpuc("bad BMP", "bad BMP");
|
||||
}
|
||||
} else {
|
||||
// V4/V5 header
|
||||
int i;
|
||||
if (hsz != 108 && hsz != 124)
|
||||
return stbi__errpuc("bad BMP", "bad BMP");
|
||||
|
@ -5345,6 +5447,8 @@ static void *stbi__bmp_parse_header(stbi__context *s, stbi__bmp_data *info)
|
|||
info->mg = stbi__get32le(s);
|
||||
info->mb = stbi__get32le(s);
|
||||
info->ma = stbi__get32le(s);
|
||||
if (compress != 3) // override mr/mg/mb unless in BI_BITFIELDS mode, as per docs
|
||||
stbi__bmp_set_mask_defaults(info, compress);
|
||||
stbi__get32le(s); // discard color space
|
||||
for (i=0; i < 12; ++i)
|
||||
stbi__get32le(s); // discard color space parameters
|
||||
|
@ -5394,8 +5498,7 @@ static void *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int req
|
|||
psize = (info.offset - info.extra_read - info.hsz) >> 2;
|
||||
}
|
||||
if (psize == 0) {
|
||||
STBI_ASSERT(info.offset == s->callback_already_read + (int) (s->img_buffer - s->img_buffer_original));
|
||||
if (info.offset != s->callback_already_read + (s->img_buffer - s->buffer_start)) {
|
||||
if (info.offset != s->callback_already_read + (s->img_buffer - s->img_buffer_original)) {
|
||||
return stbi__errpuc("bad offset", "Corrupt BMP");
|
||||
}
|
||||
}
|
||||
|
@ -6342,6 +6445,7 @@ static void *stbi__pic_load(stbi__context *s,int *px,int *py,int *comp,int req_c
|
|||
|
||||
// intermediate buffer is RGBA
|
||||
result = (stbi_uc *) stbi__malloc_mad3(x, y, 4, 0);
|
||||
if (!result) return stbi__errpuc("outofmem", "Out of memory");
|
||||
memset(result, 0xff, x*y*4);
|
||||
|
||||
if (!stbi__pic_load_core(s,x,y,comp, result)) {
|
||||
|
@ -6457,6 +6561,7 @@ static int stbi__gif_header(stbi__context *s, stbi__gif *g, int *comp, int is_in
|
|||
static int stbi__gif_info_raw(stbi__context *s, int *x, int *y, int *comp)
|
||||
{
|
||||
stbi__gif* g = (stbi__gif*) stbi__malloc(sizeof(stbi__gif));
|
||||
if (!g) return stbi__err("outofmem", "Out of memory");
|
||||
if (!stbi__gif_header(s, g, comp, 1)) {
|
||||
STBI_FREE(g);
|
||||
stbi__rewind( s );
|
||||
|
@ -6766,6 +6871,17 @@ static stbi_uc *stbi__gif_load_next(stbi__context *s, stbi__gif *g, int *comp, i
|
|||
}
|
||||
}
|
||||
|
||||
static void *stbi__load_gif_main_outofmem(stbi__gif *g, stbi_uc *out, int **delays)
|
||||
{
|
||||
STBI_FREE(g->out);
|
||||
STBI_FREE(g->history);
|
||||
STBI_FREE(g->background);
|
||||
|
||||
if (out) STBI_FREE(out);
|
||||
if (delays && *delays) STBI_FREE(*delays);
|
||||
return stbi__errpuc("outofmem", "Out of memory");
|
||||
}
|
||||
|
||||
static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y, int *z, int *comp, int req_comp)
|
||||
{
|
||||
if (stbi__gif_test(s)) {
|
||||
|
@ -6777,6 +6893,10 @@ static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y,
|
|||
int stride;
|
||||
int out_size = 0;
|
||||
int delays_size = 0;
|
||||
|
||||
STBI_NOTUSED(out_size);
|
||||
STBI_NOTUSED(delays_size);
|
||||
|
||||
memset(&g, 0, sizeof(g));
|
||||
if (delays) {
|
||||
*delays = 0;
|
||||
|
@ -6794,26 +6914,29 @@ static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y,
|
|||
|
||||
if (out) {
|
||||
void *tmp = (stbi_uc*) STBI_REALLOC_SIZED( out, out_size, layers * stride );
|
||||
if (NULL == tmp) {
|
||||
STBI_FREE(g.out);
|
||||
STBI_FREE(g.history);
|
||||
STBI_FREE(g.background);
|
||||
return stbi__errpuc("outofmem", "Out of memory");
|
||||
}
|
||||
if (!tmp)
|
||||
return stbi__load_gif_main_outofmem(&g, out, delays);
|
||||
else {
|
||||
out = (stbi_uc*) tmp;
|
||||
out_size = layers * stride;
|
||||
}
|
||||
|
||||
if (delays) {
|
||||
*delays = (int*) STBI_REALLOC_SIZED( *delays, delays_size, sizeof(int) * layers );
|
||||
int *new_delays = (int*) STBI_REALLOC_SIZED( *delays, delays_size, sizeof(int) * layers );
|
||||
if (!new_delays)
|
||||
return stbi__load_gif_main_outofmem(&g, out, delays);
|
||||
*delays = new_delays;
|
||||
delays_size = layers * sizeof(int);
|
||||
}
|
||||
} else {
|
||||
out = (stbi_uc*)stbi__malloc( layers * stride );
|
||||
if (!out)
|
||||
return stbi__load_gif_main_outofmem(&g, out, delays);
|
||||
out_size = layers * stride;
|
||||
if (delays) {
|
||||
*delays = (int*) stbi__malloc( layers * sizeof(int) );
|
||||
if (!*delays)
|
||||
return stbi__load_gif_main_outofmem(&g, out, delays);
|
||||
delays_size = layers * sizeof(int);
|
||||
}
|
||||
}
|
||||
|
@ -7138,9 +7261,10 @@ static int stbi__bmp_info(stbi__context *s, int *x, int *y, int *comp)
|
|||
|
||||
info.all_a = 255;
|
||||
p = stbi__bmp_parse_header(s, &info);
|
||||
if (p == NULL) {
|
||||
stbi__rewind( s );
|
||||
if (p == NULL)
|
||||
return 0;
|
||||
}
|
||||
if (x) *x = s->img_x;
|
||||
if (y) *y = s->img_y;
|
||||
if (comp) {
|
||||
|
@ -7206,8 +7330,8 @@ static int stbi__psd_is16(stbi__context *s)
|
|||
stbi__rewind( s );
|
||||
return 0;
|
||||
}
|
||||
(void) stbi__get32be(s);
|
||||
(void) stbi__get32be(s);
|
||||
STBI_NOTUSED(stbi__get32be(s));
|
||||
STBI_NOTUSED(stbi__get32be(s));
|
||||
depth = stbi__get16be(s);
|
||||
if (depth != 16) {
|
||||
stbi__rewind( s );
|
||||
|
@ -7286,7 +7410,6 @@ static int stbi__pic_info(stbi__context *s, int *x, int *y, int *comp)
|
|||
// Known limitations:
|
||||
// Does not support comments in the header section
|
||||
// Does not support ASCII image data (formats P2 and P3)
|
||||
// Does not support 16-bit-per-channel
|
||||
|
||||
#ifndef STBI_NO_PNM
|
||||
|
||||
|
@ -7307,7 +7430,8 @@ static void *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req
|
|||
stbi_uc *out;
|
||||
STBI_NOTUSED(ri);
|
||||
|
||||
if (!stbi__pnm_info(s, (int *)&s->img_x, (int *)&s->img_y, (int *)&s->img_n))
|
||||
ri->bits_per_channel = stbi__pnm_info(s, (int *)&s->img_x, (int *)&s->img_y, (int *)&s->img_n);
|
||||
if (ri->bits_per_channel == 0)
|
||||
return 0;
|
||||
|
||||
if (s->img_y > STBI_MAX_DIMENSIONS) return stbi__errpuc("too large","Very large image (corrupt?)");
|
||||
|
@ -7317,12 +7441,12 @@ static void *stbi__pnm_load(stbi__context *s, int *x, int *y, int *comp, int req
|
|||
*y = s->img_y;
|
||||
if (comp) *comp = s->img_n;
|
||||
|
||||
if (!stbi__mad3sizes_valid(s->img_n, s->img_x, s->img_y, 0))
|
||||
if (!stbi__mad4sizes_valid(s->img_n, s->img_x, s->img_y, ri->bits_per_channel / 8, 0))
|
||||
return stbi__errpuc("too large", "PNM too large");
|
||||
|
||||
out = (stbi_uc *) stbi__malloc_mad3(s->img_n, s->img_x, s->img_y, 0);
|
||||
out = (stbi_uc *) stbi__malloc_mad4(s->img_n, s->img_x, s->img_y, ri->bits_per_channel / 8, 0);
|
||||
if (!out) return stbi__errpuc("outofmem", "Out of memory");
|
||||
stbi__getn(s, out, s->img_n * s->img_x * s->img_y);
|
||||
stbi__getn(s, out, s->img_n * s->img_x * s->img_y * (ri->bits_per_channel / 8));
|
||||
|
||||
if (req_comp && req_comp != s->img_n) {
|
||||
out = stbi__convert_format(out, s->img_n, req_comp, s->img_x, s->img_y);
|
||||
|
@ -7398,11 +7522,19 @@ static int stbi__pnm_info(stbi__context *s, int *x, int *y, int *comp)
|
|||
stbi__pnm_skip_whitespace(s, &c);
|
||||
|
||||
maxv = stbi__pnm_getinteger(s, &c); // read max value
|
||||
|
||||
if (maxv > 255)
|
||||
return stbi__err("max value > 255", "PPM image not 8-bit");
|
||||
if (maxv > 65535)
|
||||
return stbi__err("max value > 65535", "PPM image supports only 8-bit and 16-bit images");
|
||||
else if (maxv > 255)
|
||||
return 16;
|
||||
else
|
||||
return 8;
|
||||
}
|
||||
|
||||
static int stbi__pnm_is16(stbi__context *s)
|
||||
{
|
||||
if (stbi__pnm_info(s, NULL, NULL, NULL) == 16)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -7458,6 +7590,9 @@ static int stbi__is_16_main(stbi__context *s)
|
|||
if (stbi__psd_is16(s)) return 1;
|
||||
#endif
|
||||
|
||||
#ifndef STBI_NO_PNM
|
||||
if (stbi__pnm_is16(s)) return 1;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
19
raylib/external/stb_image_resize.h
vendored
19
raylib/external/stb_image_resize.h
vendored
|
@ -1,4 +1,4 @@
|
|||
/* stb_image_resize - v0.96 - public domain image resizing
|
||||
/* stb_image_resize - v0.97 - public domain image resizing
|
||||
by Jorge L Rodriguez (@VinoBS) - 2014
|
||||
http://github.com/nothings/stb
|
||||
|
||||
|
@ -1064,7 +1064,11 @@ static void stbir__calculate_coefficients_upsample(stbir_filter filter, float sc
|
|||
total_filter += coefficient_group[i];
|
||||
}
|
||||
|
||||
STBIR_ASSERT(stbir__filter_info_table[filter].kernel((float)(in_last_pixel + 1) + 0.5f - in_center_of_out, 1/scale) == 0);
|
||||
// NOTE(fg): Not actually true in general, nor is there any reason to expect it should be.
|
||||
// It would be true in exact math but is at best approximately true in floating-point math,
|
||||
// and it would not make sense to try and put actual bounds on this here because it depends
|
||||
// on the image aspect ratio which can get pretty extreme.
|
||||
//STBIR_ASSERT(stbir__filter_info_table[filter].kernel((float)(in_last_pixel + 1) + 0.5f - in_center_of_out, 1/scale) == 0);
|
||||
|
||||
STBIR_ASSERT(total_filter > 0.9);
|
||||
STBIR_ASSERT(total_filter < 1.1f); // Make sure it's not way off.
|
||||
|
@ -1103,7 +1107,11 @@ static void stbir__calculate_coefficients_downsample(stbir_filter filter, float
|
|||
coefficient_group[i] = stbir__filter_info_table[filter].kernel(x, scale_ratio) * scale_ratio;
|
||||
}
|
||||
|
||||
STBIR_ASSERT(stbir__filter_info_table[filter].kernel((float)(out_last_pixel + 1) + 0.5f - out_center_of_in, scale_ratio) == 0);
|
||||
// NOTE(fg): Not actually true in general, nor is there any reason to expect it should be.
|
||||
// It would be true in exact math but is at best approximately true in floating-point math,
|
||||
// and it would not make sense to try and put actual bounds on this here because it depends
|
||||
// on the image aspect ratio which can get pretty extreme.
|
||||
//STBIR_ASSERT(stbir__filter_info_table[filter].kernel((float)(out_last_pixel + 1) + 0.5f - out_center_of_in, scale_ratio) == 0);
|
||||
|
||||
for (i = out_last_pixel - out_first_pixel; i >= 0; i--)
|
||||
{
|
||||
|
@ -1552,7 +1560,6 @@ static void stbir__resample_horizontal_downsample(stbir__info* stbir_info, float
|
|||
{
|
||||
int out_pixel_index = k * 1;
|
||||
float coefficient = horizontal_coefficients[coefficient_group + k - n0];
|
||||
STBIR_ASSERT(coefficient != 0);
|
||||
output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient;
|
||||
}
|
||||
}
|
||||
|
@ -1573,7 +1580,6 @@ static void stbir__resample_horizontal_downsample(stbir__info* stbir_info, float
|
|||
{
|
||||
int out_pixel_index = k * 2;
|
||||
float coefficient = horizontal_coefficients[coefficient_group + k - n0];
|
||||
STBIR_ASSERT(coefficient != 0);
|
||||
output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient;
|
||||
output_buffer[out_pixel_index + 1] += decode_buffer[in_pixel_index + 1] * coefficient;
|
||||
}
|
||||
|
@ -1595,7 +1601,6 @@ static void stbir__resample_horizontal_downsample(stbir__info* stbir_info, float
|
|||
{
|
||||
int out_pixel_index = k * 3;
|
||||
float coefficient = horizontal_coefficients[coefficient_group + k - n0];
|
||||
STBIR_ASSERT(coefficient != 0);
|
||||
output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient;
|
||||
output_buffer[out_pixel_index + 1] += decode_buffer[in_pixel_index + 1] * coefficient;
|
||||
output_buffer[out_pixel_index + 2] += decode_buffer[in_pixel_index + 2] * coefficient;
|
||||
|
@ -1618,7 +1623,6 @@ static void stbir__resample_horizontal_downsample(stbir__info* stbir_info, float
|
|||
{
|
||||
int out_pixel_index = k * 4;
|
||||
float coefficient = horizontal_coefficients[coefficient_group + k - n0];
|
||||
STBIR_ASSERT(coefficient != 0);
|
||||
output_buffer[out_pixel_index + 0] += decode_buffer[in_pixel_index + 0] * coefficient;
|
||||
output_buffer[out_pixel_index + 1] += decode_buffer[in_pixel_index + 1] * coefficient;
|
||||
output_buffer[out_pixel_index + 2] += decode_buffer[in_pixel_index + 2] * coefficient;
|
||||
|
@ -1643,7 +1647,6 @@ static void stbir__resample_horizontal_downsample(stbir__info* stbir_info, float
|
|||
int c;
|
||||
int out_pixel_index = k * channels;
|
||||
float coefficient = horizontal_coefficients[coefficient_group + k - n0];
|
||||
STBIR_ASSERT(coefficient != 0);
|
||||
for (c = 0; c < channels; c++)
|
||||
output_buffer[out_pixel_index + c] += decode_buffer[in_pixel_index + c] * coefficient;
|
||||
}
|
||||
|
|
62
raylib/external/stb_image_write.h
vendored
62
raylib/external/stb_image_write.h
vendored
|
@ -1,4 +1,4 @@
|
|||
/* stb_image_write - v1.15 - public domain - http://nothings.org/stb
|
||||
/* stb_image_write - v1.16 - public domain - http://nothings.org/stb
|
||||
writes out PNG/BMP/TGA/JPEG/HDR images to C stdio - Sean Barrett 2010-2015
|
||||
no warranty implied; use at your own risk
|
||||
|
||||
|
@ -140,6 +140,7 @@ CREDITS:
|
|||
Ivan Tikhonov
|
||||
github:ignotion
|
||||
Adam Schackart
|
||||
Andrew Kensler
|
||||
|
||||
LICENSE
|
||||
|
||||
|
@ -166,9 +167,9 @@ LICENSE
|
|||
#endif
|
||||
|
||||
#ifndef STB_IMAGE_WRITE_STATIC // C++ forbids static forward declarations
|
||||
extern int stbi_write_tga_with_rle;
|
||||
extern int stbi_write_png_compression_level;
|
||||
extern int stbi_write_force_png_filter;
|
||||
STBIWDEF int stbi_write_tga_with_rle;
|
||||
STBIWDEF int stbi_write_png_compression_level;
|
||||
STBIWDEF int stbi_write_force_png_filter;
|
||||
#endif
|
||||
|
||||
#ifndef STBI_WRITE_NO_STDIO
|
||||
|
@ -178,7 +179,7 @@ STBIWDEF int stbi_write_tga(char const *filename, int w, int h, int comp, const
|
|||
STBIWDEF int stbi_write_hdr(char const *filename, int w, int h, int comp, const float *data);
|
||||
STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const void *data, int quality);
|
||||
|
||||
#ifdef STBI_WINDOWS_UTF8
|
||||
#ifdef STBIW_WINDOWS_UTF8
|
||||
STBIWDEF int stbiw_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const wchar_t* input);
|
||||
#endif
|
||||
#endif
|
||||
|
@ -285,7 +286,7 @@ static void stbi__stdio_write(void *context, void *data, int size)
|
|||
fwrite(data,1,size,(FILE*) context);
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)
|
||||
#if defined(_WIN32) && defined(STBIW_WINDOWS_UTF8)
|
||||
#ifdef __cplusplus
|
||||
#define STBIW_EXTERN extern "C"
|
||||
#else
|
||||
|
@ -303,16 +304,16 @@ STBIWDEF int stbiw_convert_wchar_to_utf8(char *buffer, size_t bufferlen, const w
|
|||
static FILE *stbiw__fopen(char const *filename, char const *mode)
|
||||
{
|
||||
FILE *f;
|
||||
#if defined(_MSC_VER) && defined(STBI_WINDOWS_UTF8)
|
||||
#if defined(_WIN32) && defined(STBIW_WINDOWS_UTF8)
|
||||
wchar_t wMode[64];
|
||||
wchar_t wFilename[1024];
|
||||
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, filename, -1, wFilename, sizeof(wFilename)))
|
||||
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, filename, -1, wFilename, sizeof(wFilename)/sizeof(*wFilename)))
|
||||
return 0;
|
||||
|
||||
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, mode, -1, wMode, sizeof(wMode)))
|
||||
if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, mode, -1, wMode, sizeof(wMode)/sizeof(*wMode)))
|
||||
return 0;
|
||||
|
||||
#if _MSC_VER >= 1400
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||
if (0 != _wfopen_s(&f, wFilename, wMode))
|
||||
f = 0;
|
||||
#else
|
||||
|
@ -397,7 +398,7 @@ static void stbiw__putc(stbi__write_context *s, unsigned char c)
|
|||
|
||||
static void stbiw__write1(stbi__write_context *s, unsigned char a)
|
||||
{
|
||||
if (s->buf_used + 1 > sizeof(s->buffer))
|
||||
if ((size_t)s->buf_used + 1 > sizeof(s->buffer))
|
||||
stbiw__write_flush(s);
|
||||
s->buffer[s->buf_used++] = a;
|
||||
}
|
||||
|
@ -405,7 +406,7 @@ static void stbiw__write1(stbi__write_context *s, unsigned char a)
|
|||
static void stbiw__write3(stbi__write_context *s, unsigned char a, unsigned char b, unsigned char c)
|
||||
{
|
||||
int n;
|
||||
if (s->buf_used + 3 > sizeof(s->buffer))
|
||||
if ((size_t)s->buf_used + 3 > sizeof(s->buffer))
|
||||
stbiw__write_flush(s);
|
||||
n = s->buf_used;
|
||||
s->buf_used = n+3;
|
||||
|
@ -490,11 +491,22 @@ static int stbiw__outfile(stbi__write_context *s, int rgb_dir, int vdir, int x,
|
|||
|
||||
static int stbi_write_bmp_core(stbi__write_context *s, int x, int y, int comp, const void *data)
|
||||
{
|
||||
if (comp != 4) {
|
||||
// write RGB bitmap
|
||||
int pad = (-x*3) & 3;
|
||||
return stbiw__outfile(s,-1,-1,x,y,comp,1,(void *) data,0,pad,
|
||||
"11 4 22 4" "4 44 22 444444",
|
||||
'B', 'M', 14+40+(x*3+pad)*y, 0,0, 14+40, // file header
|
||||
40, x,y, 1,24, 0,0,0,0,0,0); // bitmap header
|
||||
} else {
|
||||
// RGBA bitmaps need a v4 header
|
||||
// use BI_BITFIELDS mode with 32bpp and alpha mask
|
||||
// (straight BI_RGB with alpha mask doesn't work in most readers)
|
||||
return stbiw__outfile(s,-1,-1,x,y,comp,1,(void *)data,1,0,
|
||||
"11 4 22 4" "4 44 22 444444 4444 4 444 444 444 444",
|
||||
'B', 'M', 14+108+x*y*4, 0, 0, 14+108, // file header
|
||||
108, x,y, 1,32, 3,0,0,0,0,0, 0xff0000,0xff00,0xff,0xff000000u, 0, 0,0,0, 0,0,0, 0,0,0, 0,0,0); // bitmap V4 header
|
||||
}
|
||||
}
|
||||
|
||||
STBIWDEF int stbi_write_bmp_to_func(stbi_write_func *func, void *context, int x, int y, int comp, const void *data)
|
||||
|
@ -622,6 +634,8 @@ STBIWDEF int stbi_write_tga(char const *filename, int x, int y, int comp, const
|
|||
|
||||
#define stbiw__max(a, b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
#ifndef STBI_WRITE_NO_STDIO
|
||||
|
||||
static void stbiw__linear_to_rgbe(unsigned char *rgbe, float *linear)
|
||||
{
|
||||
int exponent;
|
||||
|
@ -756,7 +770,7 @@ static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, f
|
|||
char header[] = "#?RADIANCE\n# Written by stb_image_write.h\nFORMAT=32-bit_rle_rgbe\n";
|
||||
s->func(s->context, header, sizeof(header)-1);
|
||||
|
||||
#ifdef __STDC_WANT_SECURE_LIB__
|
||||
#ifdef __STDC_LIB_EXT1__
|
||||
len = sprintf_s(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
|
||||
#else
|
||||
len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
|
||||
|
@ -777,7 +791,6 @@ STBIWDEF int stbi_write_hdr_to_func(stbi_write_func *func, void *context, int x,
|
|||
return stbi_write_hdr_core(&s, x, y, comp, (float *) data);
|
||||
}
|
||||
|
||||
#ifndef STBI_WRITE_NO_STDIO
|
||||
STBIWDEF int stbi_write_hdr(char const *filename, int x, int y, int comp, const float *data)
|
||||
{
|
||||
stbi__write_context s = { 0 };
|
||||
|
@ -968,6 +981,23 @@ STBIWDEF unsigned char * stbi_zlib_compress(unsigned char *data, int data_len, i
|
|||
(void) stbiw__sbfree(hash_table[i]);
|
||||
STBIW_FREE(hash_table);
|
||||
|
||||
// store uncompressed instead if compression was worse
|
||||
if (stbiw__sbn(out) > data_len + 2 + ((data_len+32766)/32767)*5) {
|
||||
stbiw__sbn(out) = 2; // truncate to DEFLATE 32K window and FLEVEL = 1
|
||||
for (j = 0; j < data_len;) {
|
||||
int blocklen = data_len - j;
|
||||
if (blocklen > 32767) blocklen = 32767;
|
||||
stbiw__sbpush(out, data_len - j == blocklen); // BFINAL = ?, BTYPE = 0 -- no compression
|
||||
stbiw__sbpush(out, STBIW_UCHAR(blocklen)); // LEN
|
||||
stbiw__sbpush(out, STBIW_UCHAR(blocklen >> 8));
|
||||
stbiw__sbpush(out, STBIW_UCHAR(~blocklen)); // NLEN
|
||||
stbiw__sbpush(out, STBIW_UCHAR(~blocklen >> 8));
|
||||
memcpy(out+stbiw__sbn(out), data+j, blocklen);
|
||||
stbiw__sbn(out) += blocklen;
|
||||
j += blocklen;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// compute adler32 on input
|
||||
unsigned int s1=1, s2=0;
|
||||
|
@ -1598,6 +1628,10 @@ STBIWDEF int stbi_write_jpg(char const *filename, int x, int y, int comp, const
|
|||
#endif // STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
|
||||
/* Revision history
|
||||
1.16 (2021-07-11)
|
||||
make Deflate code emit uncompressed blocks when it would otherwise expand
|
||||
support writing BMPs with alpha channel
|
||||
1.15 (2020-07-13) unknown
|
||||
1.14 (2020-02-02) updated JPEG writer to downsample chroma channels
|
||||
1.13
|
||||
1.12
|
||||
|
|
428
raylib/external/stb_perlin.h
vendored
428
raylib/external/stb_perlin.h
vendored
|
@ -1,428 +0,0 @@
|
|||
// stb_perlin.h - v0.5 - perlin noise
|
||||
// public domain single-file C implementation by Sean Barrett
|
||||
//
|
||||
// LICENSE
|
||||
//
|
||||
// See end of file.
|
||||
//
|
||||
//
|
||||
// to create the implementation,
|
||||
// #define STB_PERLIN_IMPLEMENTATION
|
||||
// in *one* C/CPP file that includes this file.
|
||||
//
|
||||
//
|
||||
// Documentation:
|
||||
//
|
||||
// float stb_perlin_noise3( float x,
|
||||
// float y,
|
||||
// float z,
|
||||
// int x_wrap=0,
|
||||
// int y_wrap=0,
|
||||
// int z_wrap=0)
|
||||
//
|
||||
// This function computes a random value at the coordinate (x,y,z).
|
||||
// Adjacent random values are continuous but the noise fluctuates
|
||||
// its randomness with period 1, i.e. takes on wholly unrelated values
|
||||
// at integer points. Specifically, this implements Ken Perlin's
|
||||
// revised noise function from 2002.
|
||||
//
|
||||
// The "wrap" parameters can be used to create wraparound noise that
|
||||
// wraps at powers of two. The numbers MUST be powers of two. Specify
|
||||
// 0 to mean "don't care". (The noise always wraps every 256 due
|
||||
// details of the implementation, even if you ask for larger or no
|
||||
// wrapping.)
|
||||
//
|
||||
// float stb_perlin_noise3_seed( float x,
|
||||
// float y,
|
||||
// float z,
|
||||
// int x_wrap=0,
|
||||
// int y_wrap=0,
|
||||
// int z_wrap=0,
|
||||
// int seed)
|
||||
//
|
||||
// As above, but 'seed' selects from multiple different variations of the
|
||||
// noise function. The current implementation only uses the bottom 8 bits
|
||||
// of 'seed', but possibly in the future more bits will be used.
|
||||
//
|
||||
//
|
||||
// Fractal Noise:
|
||||
//
|
||||
// Three common fractal noise functions are included, which produce
|
||||
// a wide variety of nice effects depending on the parameters
|
||||
// provided. Note that each function will call stb_perlin_noise3
|
||||
// 'octaves' times, so this parameter will affect runtime.
|
||||
//
|
||||
// float stb_perlin_ridge_noise3(float x, float y, float z,
|
||||
// float lacunarity, float gain, float offset, int octaves)
|
||||
//
|
||||
// float stb_perlin_fbm_noise3(float x, float y, float z,
|
||||
// float lacunarity, float gain, int octaves)
|
||||
//
|
||||
// float stb_perlin_turbulence_noise3(float x, float y, float z,
|
||||
// float lacunarity, float gain, int octaves)
|
||||
//
|
||||
// Typical values to start playing with:
|
||||
// octaves = 6 -- number of "octaves" of noise3() to sum
|
||||
// lacunarity = ~ 2.0 -- spacing between successive octaves (use exactly 2.0 for wrapping output)
|
||||
// gain = 0.5 -- relative weighting applied to each successive octave
|
||||
// offset = 1.0? -- used to invert the ridges, may need to be larger, not sure
|
||||
//
|
||||
//
|
||||
// Contributors:
|
||||
// Jack Mott - additional noise functions
|
||||
// Jordan Peck - seeded noise
|
||||
//
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
extern float stb_perlin_noise3(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap);
|
||||
extern float stb_perlin_noise3_seed(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap, int seed);
|
||||
extern float stb_perlin_ridge_noise3(float x, float y, float z, float lacunarity, float gain, float offset, int octaves);
|
||||
extern float stb_perlin_fbm_noise3(float x, float y, float z, float lacunarity, float gain, int octaves);
|
||||
extern float stb_perlin_turbulence_noise3(float x, float y, float z, float lacunarity, float gain, int octaves);
|
||||
extern float stb_perlin_noise3_wrap_nonpow2(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap, unsigned char seed);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef STB_PERLIN_IMPLEMENTATION
|
||||
|
||||
#include <math.h> // fabs()
|
||||
|
||||
// not same permutation table as Perlin's reference to avoid copyright issues;
|
||||
// Perlin's table can be found at http://mrl.nyu.edu/~perlin/noise/
|
||||
static unsigned char stb__perlin_randtab[512] =
|
||||
{
|
||||
23, 125, 161, 52, 103, 117, 70, 37, 247, 101, 203, 169, 124, 126, 44, 123,
|
||||
152, 238, 145, 45, 171, 114, 253, 10, 192, 136, 4, 157, 249, 30, 35, 72,
|
||||
175, 63, 77, 90, 181, 16, 96, 111, 133, 104, 75, 162, 93, 56, 66, 240,
|
||||
8, 50, 84, 229, 49, 210, 173, 239, 141, 1, 87, 18, 2, 198, 143, 57,
|
||||
225, 160, 58, 217, 168, 206, 245, 204, 199, 6, 73, 60, 20, 230, 211, 233,
|
||||
94, 200, 88, 9, 74, 155, 33, 15, 219, 130, 226, 202, 83, 236, 42, 172,
|
||||
165, 218, 55, 222, 46, 107, 98, 154, 109, 67, 196, 178, 127, 158, 13, 243,
|
||||
65, 79, 166, 248, 25, 224, 115, 80, 68, 51, 184, 128, 232, 208, 151, 122,
|
||||
26, 212, 105, 43, 179, 213, 235, 148, 146, 89, 14, 195, 28, 78, 112, 76,
|
||||
250, 47, 24, 251, 140, 108, 186, 190, 228, 170, 183, 139, 39, 188, 244, 246,
|
||||
132, 48, 119, 144, 180, 138, 134, 193, 82, 182, 120, 121, 86, 220, 209, 3,
|
||||
91, 241, 149, 85, 205, 150, 113, 216, 31, 100, 41, 164, 177, 214, 153, 231,
|
||||
38, 71, 185, 174, 97, 201, 29, 95, 7, 92, 54, 254, 191, 118, 34, 221,
|
||||
131, 11, 163, 99, 234, 81, 227, 147, 156, 176, 17, 142, 69, 12, 110, 62,
|
||||
27, 255, 0, 194, 59, 116, 242, 252, 19, 21, 187, 53, 207, 129, 64, 135,
|
||||
61, 40, 167, 237, 102, 223, 106, 159, 197, 189, 215, 137, 36, 32, 22, 5,
|
||||
|
||||
// and a second copy so we don't need an extra mask or static initializer
|
||||
23, 125, 161, 52, 103, 117, 70, 37, 247, 101, 203, 169, 124, 126, 44, 123,
|
||||
152, 238, 145, 45, 171, 114, 253, 10, 192, 136, 4, 157, 249, 30, 35, 72,
|
||||
175, 63, 77, 90, 181, 16, 96, 111, 133, 104, 75, 162, 93, 56, 66, 240,
|
||||
8, 50, 84, 229, 49, 210, 173, 239, 141, 1, 87, 18, 2, 198, 143, 57,
|
||||
225, 160, 58, 217, 168, 206, 245, 204, 199, 6, 73, 60, 20, 230, 211, 233,
|
||||
94, 200, 88, 9, 74, 155, 33, 15, 219, 130, 226, 202, 83, 236, 42, 172,
|
||||
165, 218, 55, 222, 46, 107, 98, 154, 109, 67, 196, 178, 127, 158, 13, 243,
|
||||
65, 79, 166, 248, 25, 224, 115, 80, 68, 51, 184, 128, 232, 208, 151, 122,
|
||||
26, 212, 105, 43, 179, 213, 235, 148, 146, 89, 14, 195, 28, 78, 112, 76,
|
||||
250, 47, 24, 251, 140, 108, 186, 190, 228, 170, 183, 139, 39, 188, 244, 246,
|
||||
132, 48, 119, 144, 180, 138, 134, 193, 82, 182, 120, 121, 86, 220, 209, 3,
|
||||
91, 241, 149, 85, 205, 150, 113, 216, 31, 100, 41, 164, 177, 214, 153, 231,
|
||||
38, 71, 185, 174, 97, 201, 29, 95, 7, 92, 54, 254, 191, 118, 34, 221,
|
||||
131, 11, 163, 99, 234, 81, 227, 147, 156, 176, 17, 142, 69, 12, 110, 62,
|
||||
27, 255, 0, 194, 59, 116, 242, 252, 19, 21, 187, 53, 207, 129, 64, 135,
|
||||
61, 40, 167, 237, 102, 223, 106, 159, 197, 189, 215, 137, 36, 32, 22, 5,
|
||||
};
|
||||
|
||||
|
||||
// perlin's gradient has 12 cases so some get used 1/16th of the time
|
||||
// and some 2/16ths. We reduce bias by changing those fractions
|
||||
// to 5/64ths and 6/64ths
|
||||
|
||||
// this array is designed to match the previous implementation
|
||||
// of gradient hash: indices[stb__perlin_randtab[i]&63]
|
||||
static unsigned char stb__perlin_randtab_grad_idx[512] =
|
||||
{
|
||||
7, 9, 5, 0, 11, 1, 6, 9, 3, 9, 11, 1, 8, 10, 4, 7,
|
||||
8, 6, 1, 5, 3, 10, 9, 10, 0, 8, 4, 1, 5, 2, 7, 8,
|
||||
7, 11, 9, 10, 1, 0, 4, 7, 5, 0, 11, 6, 1, 4, 2, 8,
|
||||
8, 10, 4, 9, 9, 2, 5, 7, 9, 1, 7, 2, 2, 6, 11, 5,
|
||||
5, 4, 6, 9, 0, 1, 1, 0, 7, 6, 9, 8, 4, 10, 3, 1,
|
||||
2, 8, 8, 9, 10, 11, 5, 11, 11, 2, 6, 10, 3, 4, 2, 4,
|
||||
9, 10, 3, 2, 6, 3, 6, 10, 5, 3, 4, 10, 11, 2, 9, 11,
|
||||
1, 11, 10, 4, 9, 4, 11, 0, 4, 11, 4, 0, 0, 0, 7, 6,
|
||||
10, 4, 1, 3, 11, 5, 3, 4, 2, 9, 1, 3, 0, 1, 8, 0,
|
||||
6, 7, 8, 7, 0, 4, 6, 10, 8, 2, 3, 11, 11, 8, 0, 2,
|
||||
4, 8, 3, 0, 0, 10, 6, 1, 2, 2, 4, 5, 6, 0, 1, 3,
|
||||
11, 9, 5, 5, 9, 6, 9, 8, 3, 8, 1, 8, 9, 6, 9, 11,
|
||||
10, 7, 5, 6, 5, 9, 1, 3, 7, 0, 2, 10, 11, 2, 6, 1,
|
||||
3, 11, 7, 7, 2, 1, 7, 3, 0, 8, 1, 1, 5, 0, 6, 10,
|
||||
11, 11, 0, 2, 7, 0, 10, 8, 3, 5, 7, 1, 11, 1, 0, 7,
|
||||
9, 0, 11, 5, 10, 3, 2, 3, 5, 9, 7, 9, 8, 4, 6, 5,
|
||||
|
||||
// and a second copy so we don't need an extra mask or static initializer
|
||||
7, 9, 5, 0, 11, 1, 6, 9, 3, 9, 11, 1, 8, 10, 4, 7,
|
||||
8, 6, 1, 5, 3, 10, 9, 10, 0, 8, 4, 1, 5, 2, 7, 8,
|
||||
7, 11, 9, 10, 1, 0, 4, 7, 5, 0, 11, 6, 1, 4, 2, 8,
|
||||
8, 10, 4, 9, 9, 2, 5, 7, 9, 1, 7, 2, 2, 6, 11, 5,
|
||||
5, 4, 6, 9, 0, 1, 1, 0, 7, 6, 9, 8, 4, 10, 3, 1,
|
||||
2, 8, 8, 9, 10, 11, 5, 11, 11, 2, 6, 10, 3, 4, 2, 4,
|
||||
9, 10, 3, 2, 6, 3, 6, 10, 5, 3, 4, 10, 11, 2, 9, 11,
|
||||
1, 11, 10, 4, 9, 4, 11, 0, 4, 11, 4, 0, 0, 0, 7, 6,
|
||||
10, 4, 1, 3, 11, 5, 3, 4, 2, 9, 1, 3, 0, 1, 8, 0,
|
||||
6, 7, 8, 7, 0, 4, 6, 10, 8, 2, 3, 11, 11, 8, 0, 2,
|
||||
4, 8, 3, 0, 0, 10, 6, 1, 2, 2, 4, 5, 6, 0, 1, 3,
|
||||
11, 9, 5, 5, 9, 6, 9, 8, 3, 8, 1, 8, 9, 6, 9, 11,
|
||||
10, 7, 5, 6, 5, 9, 1, 3, 7, 0, 2, 10, 11, 2, 6, 1,
|
||||
3, 11, 7, 7, 2, 1, 7, 3, 0, 8, 1, 1, 5, 0, 6, 10,
|
||||
11, 11, 0, 2, 7, 0, 10, 8, 3, 5, 7, 1, 11, 1, 0, 7,
|
||||
9, 0, 11, 5, 10, 3, 2, 3, 5, 9, 7, 9, 8, 4, 6, 5,
|
||||
};
|
||||
|
||||
static float stb__perlin_lerp(float a, float b, float t)
|
||||
{
|
||||
return a + (b-a) * t;
|
||||
}
|
||||
|
||||
static int stb__perlin_fastfloor(float a)
|
||||
{
|
||||
int ai = (int) a;
|
||||
return (a < ai) ? ai-1 : ai;
|
||||
}
|
||||
|
||||
// different grad function from Perlin's, but easy to modify to match reference
|
||||
static float stb__perlin_grad(int grad_idx, float x, float y, float z)
|
||||
{
|
||||
static float basis[12][4] =
|
||||
{
|
||||
{ 1, 1, 0 },
|
||||
{ -1, 1, 0 },
|
||||
{ 1,-1, 0 },
|
||||
{ -1,-1, 0 },
|
||||
{ 1, 0, 1 },
|
||||
{ -1, 0, 1 },
|
||||
{ 1, 0,-1 },
|
||||
{ -1, 0,-1 },
|
||||
{ 0, 1, 1 },
|
||||
{ 0,-1, 1 },
|
||||
{ 0, 1,-1 },
|
||||
{ 0,-1,-1 },
|
||||
};
|
||||
|
||||
float *grad = basis[grad_idx];
|
||||
return grad[0]*x + grad[1]*y + grad[2]*z;
|
||||
}
|
||||
|
||||
float stb_perlin_noise3_internal(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap, unsigned char seed)
|
||||
{
|
||||
float u,v,w;
|
||||
float n000,n001,n010,n011,n100,n101,n110,n111;
|
||||
float n00,n01,n10,n11;
|
||||
float n0,n1;
|
||||
|
||||
unsigned int x_mask = (x_wrap-1) & 255;
|
||||
unsigned int y_mask = (y_wrap-1) & 255;
|
||||
unsigned int z_mask = (z_wrap-1) & 255;
|
||||
int px = stb__perlin_fastfloor(x);
|
||||
int py = stb__perlin_fastfloor(y);
|
||||
int pz = stb__perlin_fastfloor(z);
|
||||
int x0 = px & x_mask, x1 = (px+1) & x_mask;
|
||||
int y0 = py & y_mask, y1 = (py+1) & y_mask;
|
||||
int z0 = pz & z_mask, z1 = (pz+1) & z_mask;
|
||||
int r0,r1, r00,r01,r10,r11;
|
||||
|
||||
#define stb__perlin_ease(a) (((a*6-15)*a + 10) * a * a * a)
|
||||
|
||||
x -= px; u = stb__perlin_ease(x);
|
||||
y -= py; v = stb__perlin_ease(y);
|
||||
z -= pz; w = stb__perlin_ease(z);
|
||||
|
||||
r0 = stb__perlin_randtab[x0+seed];
|
||||
r1 = stb__perlin_randtab[x1+seed];
|
||||
|
||||
r00 = stb__perlin_randtab[r0+y0];
|
||||
r01 = stb__perlin_randtab[r0+y1];
|
||||
r10 = stb__perlin_randtab[r1+y0];
|
||||
r11 = stb__perlin_randtab[r1+y1];
|
||||
|
||||
n000 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r00+z0], x , y , z );
|
||||
n001 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r00+z1], x , y , z-1 );
|
||||
n010 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r01+z0], x , y-1, z );
|
||||
n011 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r01+z1], x , y-1, z-1 );
|
||||
n100 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r10+z0], x-1, y , z );
|
||||
n101 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r10+z1], x-1, y , z-1 );
|
||||
n110 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r11+z0], x-1, y-1, z );
|
||||
n111 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r11+z1], x-1, y-1, z-1 );
|
||||
|
||||
n00 = stb__perlin_lerp(n000,n001,w);
|
||||
n01 = stb__perlin_lerp(n010,n011,w);
|
||||
n10 = stb__perlin_lerp(n100,n101,w);
|
||||
n11 = stb__perlin_lerp(n110,n111,w);
|
||||
|
||||
n0 = stb__perlin_lerp(n00,n01,v);
|
||||
n1 = stb__perlin_lerp(n10,n11,v);
|
||||
|
||||
return stb__perlin_lerp(n0,n1,u);
|
||||
}
|
||||
|
||||
float stb_perlin_noise3(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap)
|
||||
{
|
||||
return stb_perlin_noise3_internal(x,y,z,x_wrap,y_wrap,z_wrap,0);
|
||||
}
|
||||
|
||||
float stb_perlin_noise3_seed(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap, int seed)
|
||||
{
|
||||
return stb_perlin_noise3_internal(x,y,z,x_wrap,y_wrap,z_wrap, (unsigned char) seed);
|
||||
}
|
||||
|
||||
float stb_perlin_ridge_noise3(float x, float y, float z, float lacunarity, float gain, float offset, int octaves)
|
||||
{
|
||||
int i;
|
||||
float frequency = 1.0f;
|
||||
float prev = 1.0f;
|
||||
float amplitude = 0.5f;
|
||||
float sum = 0.0f;
|
||||
|
||||
for (i = 0; i < octaves; i++) {
|
||||
float r = stb_perlin_noise3_internal(x*frequency,y*frequency,z*frequency,0,0,0,(unsigned char)i);
|
||||
r = offset - (float) fabs(r);
|
||||
r = r*r;
|
||||
sum += r*amplitude*prev;
|
||||
prev = r;
|
||||
frequency *= lacunarity;
|
||||
amplitude *= gain;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
float stb_perlin_fbm_noise3(float x, float y, float z, float lacunarity, float gain, int octaves)
|
||||
{
|
||||
int i;
|
||||
float frequency = 1.0f;
|
||||
float amplitude = 1.0f;
|
||||
float sum = 0.0f;
|
||||
|
||||
for (i = 0; i < octaves; i++) {
|
||||
sum += stb_perlin_noise3_internal(x*frequency,y*frequency,z*frequency,0,0,0,(unsigned char)i)*amplitude;
|
||||
frequency *= lacunarity;
|
||||
amplitude *= gain;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
float stb_perlin_turbulence_noise3(float x, float y, float z, float lacunarity, float gain, int octaves)
|
||||
{
|
||||
int i;
|
||||
float frequency = 1.0f;
|
||||
float amplitude = 1.0f;
|
||||
float sum = 0.0f;
|
||||
|
||||
for (i = 0; i < octaves; i++) {
|
||||
float r = stb_perlin_noise3_internal(x*frequency,y*frequency,z*frequency,0,0,0,(unsigned char)i)*amplitude;
|
||||
sum += (float) fabs(r);
|
||||
frequency *= lacunarity;
|
||||
amplitude *= gain;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
float stb_perlin_noise3_wrap_nonpow2(float x, float y, float z, int x_wrap, int y_wrap, int z_wrap, unsigned char seed)
|
||||
{
|
||||
float u,v,w;
|
||||
float n000,n001,n010,n011,n100,n101,n110,n111;
|
||||
float n00,n01,n10,n11;
|
||||
float n0,n1;
|
||||
|
||||
int px = stb__perlin_fastfloor(x);
|
||||
int py = stb__perlin_fastfloor(y);
|
||||
int pz = stb__perlin_fastfloor(z);
|
||||
int x_wrap2 = (x_wrap ? x_wrap : 256);
|
||||
int y_wrap2 = (y_wrap ? y_wrap : 256);
|
||||
int z_wrap2 = (z_wrap ? z_wrap : 256);
|
||||
int x0 = px % x_wrap2, x1;
|
||||
int y0 = py % y_wrap2, y1;
|
||||
int z0 = pz % z_wrap2, z1;
|
||||
int r0,r1, r00,r01,r10,r11;
|
||||
|
||||
if (x0 < 0) x0 += x_wrap2;
|
||||
if (y0 < 0) y0 += y_wrap2;
|
||||
if (z0 < 0) z0 += z_wrap2;
|
||||
x1 = (x0+1) % x_wrap2;
|
||||
y1 = (y0+1) % y_wrap2;
|
||||
z1 = (z0+1) % z_wrap2;
|
||||
|
||||
#define stb__perlin_ease(a) (((a*6-15)*a + 10) * a * a * a)
|
||||
|
||||
x -= px; u = stb__perlin_ease(x);
|
||||
y -= py; v = stb__perlin_ease(y);
|
||||
z -= pz; w = stb__perlin_ease(z);
|
||||
|
||||
r0 = stb__perlin_randtab[x0];
|
||||
r0 = stb__perlin_randtab[r0+seed];
|
||||
r1 = stb__perlin_randtab[x1];
|
||||
r1 = stb__perlin_randtab[r1+seed];
|
||||
|
||||
r00 = stb__perlin_randtab[r0+y0];
|
||||
r01 = stb__perlin_randtab[r0+y1];
|
||||
r10 = stb__perlin_randtab[r1+y0];
|
||||
r11 = stb__perlin_randtab[r1+y1];
|
||||
|
||||
n000 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r00+z0], x , y , z );
|
||||
n001 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r00+z1], x , y , z-1 );
|
||||
n010 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r01+z0], x , y-1, z );
|
||||
n011 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r01+z1], x , y-1, z-1 );
|
||||
n100 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r10+z0], x-1, y , z );
|
||||
n101 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r10+z1], x-1, y , z-1 );
|
||||
n110 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r11+z0], x-1, y-1, z );
|
||||
n111 = stb__perlin_grad(stb__perlin_randtab_grad_idx[r11+z1], x-1, y-1, z-1 );
|
||||
|
||||
n00 = stb__perlin_lerp(n000,n001,w);
|
||||
n01 = stb__perlin_lerp(n010,n011,w);
|
||||
n10 = stb__perlin_lerp(n100,n101,w);
|
||||
n11 = stb__perlin_lerp(n110,n111,w);
|
||||
|
||||
n0 = stb__perlin_lerp(n00,n01,v);
|
||||
n1 = stb__perlin_lerp(n10,n11,v);
|
||||
|
||||
return stb__perlin_lerp(n0,n1,u);
|
||||
}
|
||||
#endif // STB_PERLIN_IMPLEMENTATION
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
This software is available under 2 licenses -- choose whichever you prefer.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE A - MIT License
|
||||
Copyright (c) 2017 Sean Barrett
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE B - Public Domain (www.unlicense.org)
|
||||
This is free and unencumbered software released into the public domain.
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
||||
software, either in source code form or as a compiled binary, for any purpose,
|
||||
commercial or non-commercial, and by any means.
|
||||
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||
software dedicate any and all copyright interest in the software to the public
|
||||
domain. We make this dedication for the benefit of the public at large and to
|
||||
the detriment of our heirs and successors. We intend this dedication to be an
|
||||
overt act of relinquishment in perpetuity of all present and future rights to
|
||||
this software under copyright law.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
35
raylib/external/stb_rect_pack.h
vendored
35
raylib/external/stb_rect_pack.h
vendored
|
@ -1,9 +1,15 @@
|
|||
// stb_rect_pack.h - v1.00 - public domain - rectangle packing
|
||||
// stb_rect_pack.h - v1.01 - public domain - rectangle packing
|
||||
// Sean Barrett 2014
|
||||
//
|
||||
// Useful for e.g. packing rectangular textures into an atlas.
|
||||
// Does not do rotation.
|
||||
//
|
||||
// Before #including,
|
||||
//
|
||||
// #define STB_RECT_PACK_IMPLEMENTATION
|
||||
//
|
||||
// in the file that you want to have the implementation.
|
||||
//
|
||||
// Not necessarily the awesomest packing method, but better than
|
||||
// the totally naive one in stb_truetype (which is primarily what
|
||||
// this is meant to replace).
|
||||
|
@ -35,6 +41,7 @@
|
|||
//
|
||||
// Version history:
|
||||
//
|
||||
// 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section
|
||||
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
|
||||
// 0.99 (2019-02-07) warning fixes
|
||||
// 0.11 (2017-03-03) return packing success/fail result
|
||||
|
@ -75,11 +82,10 @@ typedef struct stbrp_context stbrp_context;
|
|||
typedef struct stbrp_node stbrp_node;
|
||||
typedef struct stbrp_rect stbrp_rect;
|
||||
|
||||
#ifdef STBRP_LARGE_RECTS
|
||||
typedef int stbrp_coord;
|
||||
#else
|
||||
typedef unsigned short stbrp_coord;
|
||||
#endif
|
||||
|
||||
#define STBRP__MAXVAL 0x7fffffff
|
||||
// Mostly for internal use, but this is the maximum supported coordinate value.
|
||||
|
||||
STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
|
||||
// Assign packed locations to rectangles. The rectangles are of type
|
||||
|
@ -209,8 +215,10 @@ struct stbrp_context
|
|||
|
||||
#ifdef _MSC_VER
|
||||
#define STBRP__NOTUSED(v) (void)(v)
|
||||
#define STBRP__CDECL __cdecl
|
||||
#else
|
||||
#define STBRP__NOTUSED(v) (void)sizeof(v)
|
||||
#define STBRP__CDECL
|
||||
#endif
|
||||
|
||||
enum
|
||||
|
@ -253,9 +261,6 @@ STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_ou
|
|||
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
|
||||
{
|
||||
int i;
|
||||
#ifndef STBRP_LARGE_RECTS
|
||||
STBRP_ASSERT(width <= 0xffff && height <= 0xffff);
|
||||
#endif
|
||||
|
||||
for (i=0; i < num_nodes-1; ++i)
|
||||
nodes[i].next = &nodes[i+1];
|
||||
|
@ -274,11 +279,7 @@ STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height,
|
|||
context->extra[0].y = 0;
|
||||
context->extra[0].next = &context->extra[1];
|
||||
context->extra[1].x = (stbrp_coord) width;
|
||||
#ifdef STBRP_LARGE_RECTS
|
||||
context->extra[1].y = (1<<30);
|
||||
#else
|
||||
context->extra[1].y = 65535;
|
||||
#endif
|
||||
context->extra[1].next = NULL;
|
||||
}
|
||||
|
||||
|
@ -520,7 +521,7 @@ static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, i
|
|||
return res;
|
||||
}
|
||||
|
||||
static int rect_height_compare(const void *a, const void *b)
|
||||
static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
|
||||
{
|
||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||
|
@ -531,19 +532,13 @@ static int rect_height_compare(const void *a, const void *b)
|
|||
return (p->w > q->w) ? -1 : (p->w < q->w);
|
||||
}
|
||||
|
||||
static int rect_original_order(const void *a, const void *b)
|
||||
static int STBRP__CDECL rect_original_order(const void *a, const void *b)
|
||||
{
|
||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
|
||||
}
|
||||
|
||||
#ifdef STBRP_LARGE_RECTS
|
||||
#define STBRP__MAXVAL 0xffffffff
|
||||
#else
|
||||
#define STBRP__MAXVAL 0xffff
|
||||
#endif
|
||||
|
||||
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
|
||||
{
|
||||
int i, all_rects_packed = 1;
|
||||
|
|
258
raylib/external/stb_truetype.h
vendored
258
raylib/external/stb_truetype.h
vendored
|
@ -1,5 +1,5 @@
|
|||
// stb_truetype.h - v1.24 - public domain
|
||||
// authored from 2009-2020 by Sean Barrett / RAD Game Tools
|
||||
// stb_truetype.h - v1.26 - public domain
|
||||
// authored from 2009-2021 by Sean Barrett / RAD Game Tools
|
||||
//
|
||||
// =======================================================================
|
||||
//
|
||||
|
@ -58,6 +58,8 @@
|
|||
//
|
||||
// VERSION HISTORY
|
||||
//
|
||||
// 1.26 (2021-08-28) fix broken rasterizer
|
||||
// 1.25 (2021-07-11) many fixes
|
||||
// 1.24 (2020-02-05) fix warning
|
||||
// 1.23 (2020-02-02) query SVG data for glyphs; query whole kerning table (but only kern not GPOS)
|
||||
// 1.22 (2019-08-11) minimize missing-glyph duplication; fix kerning if both 'GPOS' and 'kern' are defined
|
||||
|
@ -270,8 +272,8 @@
|
|||
//// SAMPLE PROGRAMS
|
||||
////
|
||||
//
|
||||
// Incomplete text-in-3d-api example, which draws quads properly aligned to be lossless
|
||||
//
|
||||
// Incomplete text-in-3d-api example, which draws quads properly aligned to be lossless.
|
||||
// See "tests/truetype_demo_win32.c" for a complete version.
|
||||
#if 0
|
||||
#define STB_TRUETYPE_IMPLEMENTATION // force following include to generate implementation
|
||||
#include "stb_truetype.h"
|
||||
|
@ -297,6 +299,8 @@ void my_stbtt_initfont(void)
|
|||
void my_stbtt_print(float x, float y, char *text)
|
||||
{
|
||||
// assume orthographic projection with units = screen pixels, origin at top left
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, ftex);
|
||||
glBegin(GL_QUADS);
|
||||
|
@ -304,10 +308,10 @@ void my_stbtt_print(float x, float y, char *text)
|
|||
if (*text >= 32 && *text < 128) {
|
||||
stbtt_aligned_quad q;
|
||||
stbtt_GetBakedQuad(cdata, 512,512, *text-32, &x,&y,&q,1);//1=opengl & d3d10+,0=d3d9
|
||||
glTexCoord2f(q.s0,q.t1); glVertex2f(q.x0,q.y0);
|
||||
glTexCoord2f(q.s1,q.t1); glVertex2f(q.x1,q.y0);
|
||||
glTexCoord2f(q.s1,q.t0); glVertex2f(q.x1,q.y1);
|
||||
glTexCoord2f(q.s0,q.t0); glVertex2f(q.x0,q.y1);
|
||||
glTexCoord2f(q.s0,q.t0); glVertex2f(q.x0,q.y0);
|
||||
glTexCoord2f(q.s1,q.t0); glVertex2f(q.x1,q.y0);
|
||||
glTexCoord2f(q.s1,q.t1); glVertex2f(q.x1,q.y1);
|
||||
glTexCoord2f(q.s0,q.t1); glVertex2f(q.x0,q.y1);
|
||||
}
|
||||
++text;
|
||||
}
|
||||
|
@ -853,6 +857,7 @@ STBTT_DEF int stbtt_GetGlyphShape(const stbtt_fontinfo *info, int glyph_index, s
|
|||
STBTT_DEF void stbtt_FreeShape(const stbtt_fontinfo *info, stbtt_vertex *vertices);
|
||||
// frees the data allocated above
|
||||
|
||||
STBTT_DEF unsigned char *stbtt_FindSVGDoc(const stbtt_fontinfo *info, int gl);
|
||||
STBTT_DEF int stbtt_GetCodepointSVG(const stbtt_fontinfo *info, int unicode_codepoint, const char **svg);
|
||||
STBTT_DEF int stbtt_GetGlyphSVG(const stbtt_fontinfo *info, int gl, const char **svg);
|
||||
// fills svg with the character's SVG data.
|
||||
|
@ -1539,12 +1544,12 @@ STBTT_DEF int stbtt_FindGlyphIndex(const stbtt_fontinfo *info, int unicode_codep
|
|||
search += 2;
|
||||
|
||||
{
|
||||
stbtt_uint16 offset, start;
|
||||
stbtt_uint16 offset, start, last;
|
||||
stbtt_uint16 item = (stbtt_uint16) ((search - endCount) >> 1);
|
||||
|
||||
STBTT_assert(unicode_codepoint <= ttUSHORT(data + endCount + 2*item));
|
||||
start = ttUSHORT(data + index_map + 14 + segcount*2 + 2 + 2*item);
|
||||
if (unicode_codepoint < start)
|
||||
last = ttUSHORT(data + endCount + 2*item);
|
||||
if (unicode_codepoint < start || unicode_codepoint > last)
|
||||
return 0;
|
||||
|
||||
offset = ttUSHORT(data + index_map + 14 + segcount*6 + 2 + 2*item);
|
||||
|
@ -1871,7 +1876,7 @@ static int stbtt__GetGlyphShapeTT(const stbtt_fontinfo *info, int glyph_index, s
|
|||
if (comp_verts) STBTT_free(comp_verts, info->userdata);
|
||||
return 0;
|
||||
}
|
||||
if (num_vertices > 0) STBTT_memcpy(tmp, vertices, num_vertices*sizeof(stbtt_vertex));
|
||||
if (num_vertices > 0 && vertices) STBTT_memcpy(tmp, vertices, num_vertices*sizeof(stbtt_vertex));
|
||||
STBTT_memcpy(tmp+num_vertices, comp_verts, comp_num_verts*sizeof(stbtt_vertex));
|
||||
if (vertices) STBTT_free(vertices, info->userdata);
|
||||
vertices = tmp;
|
||||
|
@ -2134,7 +2139,7 @@ static int stbtt__run_charstring(const stbtt_fontinfo *info, int glyph_index, st
|
|||
subrs = stbtt__cid_get_glyph_subrs(info, glyph_index);
|
||||
has_subrs = 1;
|
||||
}
|
||||
// fallthrough
|
||||
// FALLTHROUGH
|
||||
case 0x1D: // callgsubr
|
||||
if (sp < 1) return STBTT__CSERR("call(g|)subr stack");
|
||||
v = (int) s[--sp];
|
||||
|
@ -2239,7 +2244,7 @@ static int stbtt__run_charstring(const stbtt_fontinfo *info, int glyph_index, st
|
|||
} break;
|
||||
|
||||
default:
|
||||
if (b0 != 255 && b0 != 28 && (b0 < 32 || b0 > 254))
|
||||
if (b0 != 255 && b0 != 28 && b0 < 32)
|
||||
return STBTT__CSERR("reserved operator");
|
||||
|
||||
// push immediate
|
||||
|
@ -2384,7 +2389,7 @@ static int stbtt__GetGlyphKernInfoAdvance(const stbtt_fontinfo *info, int glyph
|
|||
static stbtt_int32 stbtt__GetCoverageIndex(stbtt_uint8 *coverageTable, int glyph)
|
||||
{
|
||||
stbtt_uint16 coverageFormat = ttUSHORT(coverageTable);
|
||||
switch(coverageFormat) {
|
||||
switch (coverageFormat) {
|
||||
case 1: {
|
||||
stbtt_uint16 glyphCount = ttUSHORT(coverageTable + 2);
|
||||
|
||||
|
@ -2405,7 +2410,8 @@ static stbtt_int32 stbtt__GetCoverageIndex(stbtt_uint8 *coverageTable, int glyp
|
|||
return m;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
|
||||
case 2: {
|
||||
stbtt_uint16 rangeCount = ttUSHORT(coverageTable + 2);
|
||||
|
@ -2429,12 +2435,10 @@ static stbtt_int32 stbtt__GetCoverageIndex(stbtt_uint8 *coverageTable, int glyp
|
|||
return startCoverageIndex + glyph - strawStart;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
// There are no other cases.
|
||||
STBTT_assert(0);
|
||||
} break;
|
||||
default: return -1; // unsupported
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
@ -2443,7 +2447,7 @@ static stbtt_int32 stbtt__GetCoverageIndex(stbtt_uint8 *coverageTable, int glyp
|
|||
static stbtt_int32 stbtt__GetGlyphClass(stbtt_uint8 *classDefTable, int glyph)
|
||||
{
|
||||
stbtt_uint16 classDefFormat = ttUSHORT(classDefTable);
|
||||
switch(classDefFormat)
|
||||
switch (classDefFormat)
|
||||
{
|
||||
case 1: {
|
||||
stbtt_uint16 startGlyphID = ttUSHORT(classDefTable + 2);
|
||||
|
@ -2452,9 +2456,8 @@ static stbtt_int32 stbtt__GetGlyphClass(stbtt_uint8 *classDefTable, int glyph)
|
|||
|
||||
if (glyph >= startGlyphID && glyph < startGlyphID + glyphCount)
|
||||
return (stbtt_int32)ttUSHORT(classDef1ValueArray + 2 * (glyph - startGlyphID));
|
||||
|
||||
classDefTable = classDef1ValueArray + 2 * glyphCount;
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
|
||||
case 2: {
|
||||
stbtt_uint16 classRangeCount = ttUSHORT(classDefTable + 2);
|
||||
|
@ -2476,17 +2479,15 @@ static stbtt_int32 stbtt__GetGlyphClass(stbtt_uint8 *classDefTable, int glyph)
|
|||
else
|
||||
return (stbtt_int32)ttUSHORT(classRangeRecord + 4);
|
||||
}
|
||||
|
||||
classDefTable = classRangeRecords + 6 * classRangeCount;
|
||||
} break;
|
||||
|
||||
default: {
|
||||
// There are no other cases.
|
||||
STBTT_assert(0);
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
default:
|
||||
return -1; // Unsupported definition type, return an error.
|
||||
}
|
||||
|
||||
// "All glyphs not assigned to a class fall into class 0". (OpenType spec)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Define to STBTT_assert(x) if you want to break on unimplemented formats.
|
||||
|
@ -2498,7 +2499,7 @@ static stbtt_int32 stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, i
|
|||
stbtt_uint8 *lookupList;
|
||||
stbtt_uint16 lookupCount;
|
||||
stbtt_uint8 *data;
|
||||
stbtt_int32 i;
|
||||
stbtt_int32 i, sti;
|
||||
|
||||
if (!info->gpos) return 0;
|
||||
|
||||
|
@ -2518,9 +2519,9 @@ static stbtt_int32 stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, i
|
|||
stbtt_uint16 lookupType = ttUSHORT(lookupTable);
|
||||
stbtt_uint16 subTableCount = ttUSHORT(lookupTable + 4);
|
||||
stbtt_uint8 *subTableOffsets = lookupTable + 6;
|
||||
switch(lookupType) {
|
||||
case 2: { // Pair Adjustment Positioning Subtable
|
||||
stbtt_int32 sti;
|
||||
if (lookupType != 2) // Pair Adjustment Positioning Subtable
|
||||
continue;
|
||||
|
||||
for (sti=0; sti<subTableCount; sti++) {
|
||||
stbtt_uint16 subtableOffset = ttUSHORT(subTableOffsets + 2 * sti);
|
||||
stbtt_uint8 *table = lookupTable + subtableOffset;
|
||||
|
@ -2535,20 +2536,15 @@ static stbtt_int32 stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, i
|
|||
int straw, needle;
|
||||
stbtt_uint16 valueFormat1 = ttUSHORT(table + 4);
|
||||
stbtt_uint16 valueFormat2 = ttUSHORT(table + 6);
|
||||
if (valueFormat1 == 4 && valueFormat2 == 0) { // Support more formats?
|
||||
stbtt_int32 valueRecordPairSizeInBytes = 2;
|
||||
stbtt_uint16 pairSetCount = ttUSHORT(table + 8);
|
||||
stbtt_uint16 pairPosOffset = ttUSHORT(table + 10 + 2 * coverageIndex);
|
||||
stbtt_uint8 *pairValueTable = table + pairPosOffset;
|
||||
stbtt_uint16 pairValueCount = ttUSHORT(pairValueTable);
|
||||
stbtt_uint8 *pairValueArray = pairValueTable + 2;
|
||||
// TODO: Support more formats.
|
||||
STBTT_GPOS_TODO_assert(valueFormat1 == 4);
|
||||
if (valueFormat1 != 4) return 0;
|
||||
STBTT_GPOS_TODO_assert(valueFormat2 == 0);
|
||||
if (valueFormat2 != 0) return 0;
|
||||
|
||||
STBTT_assert(coverageIndex < pairSetCount);
|
||||
STBTT__NOTUSED(pairSetCount);
|
||||
if (coverageIndex >= pairSetCount) return 0;
|
||||
|
||||
needle=glyph2;
|
||||
r=pairValueCount-1;
|
||||
|
@ -2571,12 +2567,15 @@ static stbtt_int32 stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, i
|
|||
return xAdvance;
|
||||
}
|
||||
}
|
||||
} break;
|
||||
} else
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
|
||||
case 2: {
|
||||
stbtt_uint16 valueFormat1 = ttUSHORT(table + 4);
|
||||
stbtt_uint16 valueFormat2 = ttUSHORT(table + 6);
|
||||
|
||||
if (valueFormat1 == 4 && valueFormat2 == 0) { // Support more formats?
|
||||
stbtt_uint16 classDef1Offset = ttUSHORT(table + 8);
|
||||
stbtt_uint16 classDef2Offset = ttUSHORT(table + 10);
|
||||
int glyph1class = stbtt__GetGlyphClass(table + classDef1Offset, glyph1);
|
||||
|
@ -2584,36 +2583,24 @@ static stbtt_int32 stbtt__GetGlyphGPOSInfoAdvance(const stbtt_fontinfo *info, i
|
|||
|
||||
stbtt_uint16 class1Count = ttUSHORT(table + 12);
|
||||
stbtt_uint16 class2Count = ttUSHORT(table + 14);
|
||||
STBTT_assert(glyph1class < class1Count);
|
||||
STBTT_assert(glyph2class < class2Count);
|
||||
stbtt_uint8 *class1Records, *class2Records;
|
||||
stbtt_int16 xAdvance;
|
||||
|
||||
// TODO: Support more formats.
|
||||
STBTT_GPOS_TODO_assert(valueFormat1 == 4);
|
||||
if (valueFormat1 != 4) return 0;
|
||||
STBTT_GPOS_TODO_assert(valueFormat2 == 0);
|
||||
if (valueFormat2 != 0) return 0;
|
||||
if (glyph1class < 0 || glyph1class >= class1Count) return 0; // malformed
|
||||
if (glyph2class < 0 || glyph2class >= class2Count) return 0; // malformed
|
||||
|
||||
if (glyph1class >= 0 && glyph1class < class1Count && glyph2class >= 0 && glyph2class < class2Count) {
|
||||
stbtt_uint8 *class1Records = table + 16;
|
||||
stbtt_uint8 *class2Records = class1Records + 2 * (glyph1class * class2Count);
|
||||
stbtt_int16 xAdvance = ttSHORT(class2Records + 2 * glyph2class);
|
||||
class1Records = table + 16;
|
||||
class2Records = class1Records + 2 * (glyph1class * class2Count);
|
||||
xAdvance = ttSHORT(class2Records + 2 * glyph2class);
|
||||
return xAdvance;
|
||||
}
|
||||
} break;
|
||||
|
||||
default: {
|
||||
// There are no other cases.
|
||||
STBTT_assert(0);
|
||||
} else
|
||||
return 0;
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
break;
|
||||
};
|
||||
|
||||
default:
|
||||
// TODO: Implement other stuff.
|
||||
break;
|
||||
return 0; // Unsupported position format
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3075,6 +3062,23 @@ static void stbtt__handle_clipped_edge(float *scanline, int x, stbtt__active_edg
|
|||
}
|
||||
}
|
||||
|
||||
static float stbtt__sized_trapezoid_area(float height, float top_width, float bottom_width)
|
||||
{
|
||||
STBTT_assert(top_width >= 0);
|
||||
STBTT_assert(bottom_width >= 0);
|
||||
return (top_width + bottom_width) / 2.0f * height;
|
||||
}
|
||||
|
||||
static float stbtt__position_trapezoid_area(float height, float tx0, float tx1, float bx0, float bx1)
|
||||
{
|
||||
return stbtt__sized_trapezoid_area(height, tx1 - tx0, bx1 - bx0);
|
||||
}
|
||||
|
||||
static float stbtt__sized_triangle_area(float height, float width)
|
||||
{
|
||||
return height * width / 2;
|
||||
}
|
||||
|
||||
static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill, int len, stbtt__active_edge *e, float y_top)
|
||||
{
|
||||
float y_bottom = y_top+1;
|
||||
|
@ -3129,13 +3133,13 @@ static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill,
|
|||
float height;
|
||||
// simple case, only spans one pixel
|
||||
int x = (int) x_top;
|
||||
height = sy1 - sy0;
|
||||
height = (sy1 - sy0) * e->direction;
|
||||
STBTT_assert(x >= 0 && x < len);
|
||||
scanline[x] += e->direction * (1-((x_top - x) + (x_bottom-x))/2) * height;
|
||||
scanline_fill[x] += e->direction * height; // everything right of this pixel is filled
|
||||
scanline[x] += stbtt__position_trapezoid_area(height, x_top, x+1.0f, x_bottom, x+1.0f);
|
||||
scanline_fill[x] += height; // everything right of this pixel is filled
|
||||
} else {
|
||||
int x,x1,x2;
|
||||
float y_crossing, step, sign, area;
|
||||
float y_crossing, y_final, step, sign, area;
|
||||
// covers 2+ pixels
|
||||
if (x_top > x_bottom) {
|
||||
// flip scanline vertically; signed area is the same
|
||||
|
@ -3148,29 +3152,79 @@ static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill,
|
|||
dy = -dy;
|
||||
t = x0, x0 = xb, xb = t;
|
||||
}
|
||||
STBTT_assert(dy >= 0);
|
||||
STBTT_assert(dx >= 0);
|
||||
|
||||
x1 = (int) x_top;
|
||||
x2 = (int) x_bottom;
|
||||
// compute intersection with y axis at x1+1
|
||||
y_crossing = (x1+1 - x0) * dy + y_top;
|
||||
y_crossing = y_top + dy * (x1+1 - x0);
|
||||
|
||||
// compute intersection with y axis at x2
|
||||
y_final = y_top + dy * (x2 - x0);
|
||||
|
||||
// x1 x_top x2 x_bottom
|
||||
// y_top +------|-----+------------+------------+--------|---+------------+
|
||||
// | | | | | |
|
||||
// | | | | | |
|
||||
// sy0 | Txxxxx|............|............|............|............|
|
||||
// y_crossing | *xxxxx.......|............|............|............|
|
||||
// | | xxxxx..|............|............|............|
|
||||
// | | /- xx*xxxx........|............|............|
|
||||
// | | dy < | xxxxxx..|............|............|
|
||||
// y_final | | \- | xx*xxx.........|............|
|
||||
// sy1 | | | | xxxxxB...|............|
|
||||
// | | | | | |
|
||||
// | | | | | |
|
||||
// y_bottom +------------+------------+------------+------------+------------+
|
||||
//
|
||||
// goal is to measure the area covered by '.' in each pixel
|
||||
|
||||
// if x2 is right at the right edge of x1, y_crossing can blow up, github #1057
|
||||
// @TODO: maybe test against sy1 rather than y_bottom?
|
||||
if (y_crossing > y_bottom)
|
||||
y_crossing = y_bottom;
|
||||
|
||||
sign = e->direction;
|
||||
// area of the rectangle covered from y0..y_crossing
|
||||
area = sign * (y_crossing-sy0);
|
||||
// area of the triangle (x_top,y0), (x+1,y0), (x+1,y_crossing)
|
||||
scanline[x1] += area * (1-((x_top - x1)+(x1+1-x1))/2);
|
||||
|
||||
step = sign * dy;
|
||||
// area of the rectangle covered from sy0..y_crossing
|
||||
area = sign * (y_crossing-sy0);
|
||||
|
||||
// area of the triangle (x_top,sy0), (x1+1,sy0), (x1+1,y_crossing)
|
||||
scanline[x1] += stbtt__sized_triangle_area(area, x1+1 - x_top);
|
||||
|
||||
// check if final y_crossing is blown up; no test case for this
|
||||
if (y_final > y_bottom) {
|
||||
y_final = y_bottom;
|
||||
dy = (y_final - y_crossing ) / (x2 - (x1+1)); // if denom=0, y_final = y_crossing, so y_final <= y_bottom
|
||||
}
|
||||
|
||||
// in second pixel, area covered by line segment found in first pixel
|
||||
// is always a rectangle 1 wide * the height of that line segment; this
|
||||
// is exactly what the variable 'area' stores. it also gets a contribution
|
||||
// from the line segment within it. the THIRD pixel will get the first
|
||||
// pixel's rectangle contribution, the second pixel's rectangle contribution,
|
||||
// and its own contribution. the 'own contribution' is the same in every pixel except
|
||||
// the leftmost and rightmost, a trapezoid that slides down in each pixel.
|
||||
// the second pixel's contribution to the third pixel will be the
|
||||
// rectangle 1 wide times the height change in the second pixel, which is dy.
|
||||
|
||||
step = sign * dy * 1; // dy is dy/dx, change in y for every 1 change in x,
|
||||
// which multiplied by 1-pixel-width is how much pixel area changes for each step in x
|
||||
// so the area advances by 'step' every time
|
||||
|
||||
for (x = x1+1; x < x2; ++x) {
|
||||
scanline[x] += area + step/2;
|
||||
scanline[x] += area + step/2; // area of trapezoid is 1*step/2
|
||||
area += step;
|
||||
}
|
||||
y_crossing += dy * (x2 - (x1+1));
|
||||
STBTT_assert(STBTT_fabs(area) <= 1.01f); // accumulated error from area += step unless we round step down
|
||||
STBTT_assert(sy1 > y_final-0.01f);
|
||||
|
||||
STBTT_assert(STBTT_fabs(area) <= 1.01f);
|
||||
|
||||
scanline[x2] += area + sign * (1-((x2-x2)+(x_bottom-x2))/2) * (sy1-y_crossing);
|
||||
// area covered in the last pixel is the rectangle from all the pixels to the left,
|
||||
// plus the trapezoid filled by the line segment in this pixel all the way to the right edge
|
||||
scanline[x2] += area + sign * stbtt__position_trapezoid_area(sy1-y_final, (float) x2, x2+1.0f, x_bottom, x2+1.0f);
|
||||
|
||||
// the rest of the line is filled based on the total height of the line segment in this pixel
|
||||
scanline_fill[x2] += sign * (sy1-sy0);
|
||||
}
|
||||
} else {
|
||||
|
@ -3178,6 +3232,9 @@ static void stbtt__fill_active_edges_new(float *scanline, float *scanline_fill,
|
|||
// clipping logic. since this does not match the intended use
|
||||
// of this library, we use a different, very slow brute
|
||||
// force implementation
|
||||
// note though that this does happen some of the time because
|
||||
// x_top and x_bottom can be extrapolated at the top & bottom of
|
||||
// the shape and actually lie outside the bounding box
|
||||
int x;
|
||||
for (x=0; x < len; ++x) {
|
||||
// cases:
|
||||
|
@ -4414,15 +4471,14 @@ static int stbtt__compute_crossings_x(float x, float y, int nverts, stbtt_vertex
|
|||
float y_frac;
|
||||
int winding = 0;
|
||||
|
||||
orig[0] = x;
|
||||
orig[1] = y;
|
||||
|
||||
// make sure y never passes through a vertex of the shape
|
||||
y_frac = (float) STBTT_fmod(y, 1.0f);
|
||||
if (y_frac < 0.01f)
|
||||
y += 0.01f;
|
||||
else if (y_frac > 0.99f)
|
||||
y -= 0.01f;
|
||||
|
||||
orig[0] = x;
|
||||
orig[1] = y;
|
||||
|
||||
// test a ray from (-infinity,y) to (x,y)
|
||||
|
@ -4484,7 +4540,7 @@ static float stbtt__cuberoot( float x )
|
|||
return (float) STBTT_pow( x,1.0f/3.0f);
|
||||
}
|
||||
|
||||
// x^3 + c*x^2 + b*x + a = 0
|
||||
// x^3 + a*x^2 + b*x + c = 0
|
||||
static int stbtt__solve_cubic(float a, float b, float c, float* r)
|
||||
{
|
||||
float s = -a / 3;
|
||||
|
@ -4589,18 +4645,17 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
|
|||
for (i=0; i < num_verts; ++i) {
|
||||
float x0 = verts[i].x*scale_x, y0 = verts[i].y*scale_y;
|
||||
|
||||
// check against every point here rather than inside line/curve primitives -- @TODO: wrong if multiple 'moves' in a row produce a garbage point, and given culling, probably more efficient to do within line/curve
|
||||
float dist2 = (x0-sx)*(x0-sx) + (y0-sy)*(y0-sy);
|
||||
if (verts[i].type == STBTT_vline && precompute[i] != 0.0f) {
|
||||
float x1 = verts[i-1].x*scale_x, y1 = verts[i-1].y*scale_y;
|
||||
|
||||
float dist,dist2 = (x0-sx)*(x0-sx) + (y0-sy)*(y0-sy);
|
||||
if (dist2 < min_dist*min_dist)
|
||||
min_dist = (float) STBTT_sqrt(dist2);
|
||||
|
||||
if (verts[i].type == STBTT_vline) {
|
||||
float x1 = verts[i-1].x*scale_x, y1 = verts[i-1].y*scale_y;
|
||||
|
||||
// coarse culling against bbox
|
||||
//if (sx > STBTT_min(x0,x1)-min_dist && sx < STBTT_max(x0,x1)+min_dist &&
|
||||
// sy > STBTT_min(y0,y1)-min_dist && sy < STBTT_max(y0,y1)+min_dist)
|
||||
float dist = (float) STBTT_fabs((x1-x0)*(y0-sy) - (y1-y0)*(x0-sx)) * precompute[i];
|
||||
dist = (float) STBTT_fabs((x1-x0)*(y0-sy) - (y1-y0)*(x0-sx)) * precompute[i];
|
||||
STBTT_assert(i != 0);
|
||||
if (dist < min_dist) {
|
||||
// check position along line
|
||||
|
@ -4627,7 +4682,8 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
|
|||
float ax = x1-x0, ay = y1-y0;
|
||||
float bx = x0 - 2*x1 + x2, by = y0 - 2*y1 + y2;
|
||||
float mx = x0 - sx, my = y0 - sy;
|
||||
float res[3],px,py,t,it;
|
||||
float res[3] = {0.f,0.f,0.f};
|
||||
float px,py,t,it,dist2;
|
||||
float a_inv = precompute[i];
|
||||
if (a_inv == 0.0) { // if a_inv is 0, it's 2nd degree so use quadratic formula
|
||||
float a = 3*(ax*bx + ay*by);
|
||||
|
@ -4654,6 +4710,10 @@ STBTT_DEF unsigned char * stbtt_GetGlyphSDF(const stbtt_fontinfo *info, float sc
|
|||
float d = (mx*ax+my*ay) * a_inv;
|
||||
num = stbtt__solve_cubic(b, c, d, res);
|
||||
}
|
||||
dist2 = (x0-sx)*(x0-sx) + (y0-sy)*(y0-sy);
|
||||
if (dist2 < min_dist*min_dist)
|
||||
min_dist = (float) STBTT_sqrt(dist2);
|
||||
|
||||
if (num >= 1 && res[0] >= 0.0f && res[0] <= 1.0f) {
|
||||
t = res[0], it = 1.0f - t;
|
||||
px = it*it*x0 + 2*t*it*x1 + t*t*x2;
|
||||
|
@ -4913,6 +4973,12 @@ STBTT_DEF int stbtt_CompareUTF8toUTF16_bigendian(const char *s1, int len1, const
|
|||
|
||||
// FULL VERSION HISTORY
|
||||
//
|
||||
// 1.25 (2021-07-11) many fixes
|
||||
// 1.24 (2020-02-05) fix warning
|
||||
// 1.23 (2020-02-02) query SVG data for glyphs; query whole kerning table (but only kern not GPOS)
|
||||
// 1.22 (2019-08-11) minimize missing-glyph duplication; fix kerning if both 'GPOS' and 'kern' are defined
|
||||
// 1.21 (2019-02-25) fix warning
|
||||
// 1.20 (2019-02-07) PackFontRange skips missing codepoints; GetScaleFontVMetrics()
|
||||
// 1.19 (2018-02-11) OpenType GPOS kerning (horizontal only), STBTT_fmod
|
||||
// 1.18 (2018-01-29) add missing function
|
||||
// 1.17 (2017-07-23) make more arguments const; doc fix
|
||||
|
|
2
raylib/external/tinyobj_loader_c.h
vendored
2
raylib/external/tinyobj_loader_c.h
vendored
|
@ -948,6 +948,8 @@ static int tinyobj_parse_and_index_mtl_file(tinyobj_material_t **materials_out,
|
|||
/* @todo { unknown parameter } */
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
if (material.name) {
|
||||
/* Flush last material element */
|
||||
materials = tinyobj_material_add(materials, num_materials, &material);
|
||||
|
|
710
raylib/external/vox_loader.h
vendored
Normal file
710
raylib/external/vox_loader.h
vendored
Normal file
|
@ -0,0 +1,710 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2021 Johann Nadalutti.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
vox_loader - v1.01
|
||||
no warranty implied; use at your own risk
|
||||
|
||||
Do this:
|
||||
#define VOX_LOADER_INCLUDE__H
|
||||
before you include this file in* one* C or C++ file to create the implementation.
|
||||
|
||||
// i.e. it should look like this:
|
||||
#include ...
|
||||
#include ...
|
||||
#include ...
|
||||
#define VOX_LOADER_INCLUDE__H
|
||||
#include "vox_loader.h"
|
||||
|
||||
revision history:
|
||||
1.00 (2021-09-03) first released version
|
||||
1.01 (2021-09-07) Support custom memory allocators
|
||||
Removed Raylib dependencies
|
||||
Changed Vox_LoadFileName to Vox_LoadFromMemory
|
||||
1.02 (2021-09-10) @raysan5: Reviewed some formating
|
||||
1.03 (2021-10-02) @catmanl: Reduce warnings on gcc
|
||||
1.04 (2021-10-17) @warzes: Fixing the error of loading VOX models
|
||||
|
||||
*/
|
||||
|
||||
#ifndef VOX_LOADER_H
|
||||
#define VOX_LOADER_H
|
||||
|
||||
// Allow custom memory allocators
|
||||
#ifndef VOX_MALLOC
|
||||
#define VOX_MALLOC(sz) malloc(sz)
|
||||
#endif
|
||||
#ifndef VOX_CALLOC
|
||||
#define VOX_CALLOC(n,sz) calloc(n,sz)
|
||||
#endif
|
||||
#ifndef VOX_REALLOC
|
||||
#define VOX_REALLOC(n,sz) realloc(n,sz)
|
||||
#endif
|
||||
#ifndef VOX_FREE
|
||||
#define VOX_FREE(p) free(p)
|
||||
#endif
|
||||
|
||||
#define VOX_SUCCESS (0)
|
||||
#define VOX_ERROR_FILE_NOT_FOUND (-1)
|
||||
#define VOX_ERROR_INVALID_FORMAT (-2)
|
||||
#define VOX_ERROR_FILE_VERSION_TOO_OLD (-3)
|
||||
|
||||
// VoxColor, 4 components, R8G8B8A8 (32bit)
|
||||
typedef struct {
|
||||
unsigned char r, g, b, a;
|
||||
} VoxColor;
|
||||
|
||||
// VoxVector3, 3 components
|
||||
typedef struct {
|
||||
float x, y, z;
|
||||
} VoxVector3;
|
||||
|
||||
typedef struct {
|
||||
VoxVector3* array;
|
||||
int used, size;
|
||||
} ArrayVector3;
|
||||
|
||||
typedef struct {
|
||||
VoxColor* array;
|
||||
int used, size;
|
||||
} ArrayColor;
|
||||
|
||||
typedef struct {
|
||||
unsigned short* array;
|
||||
int used, size;
|
||||
} ArrayUShort;
|
||||
|
||||
// A chunk that contain voxels
|
||||
typedef struct {
|
||||
unsigned char* m_array; //If Sparse != null
|
||||
int arraySize; //Size for m_array in bytes (DEBUG ONLY)
|
||||
} CubeChunk3D;
|
||||
|
||||
// Array for voxels
|
||||
// Array is divised into chunks of CHUNKSIZE*CHUNKSIZE*CHUNKSIZE voxels size
|
||||
typedef struct {
|
||||
// Array size in voxels
|
||||
int sizeX;
|
||||
int sizeY;
|
||||
int sizeZ;
|
||||
|
||||
// Chunks size into array (array is divised into chunks)
|
||||
int chunksSizeX;
|
||||
int chunksSizeY;
|
||||
int chunksSizeZ;
|
||||
|
||||
// Chunks array
|
||||
CubeChunk3D* m_arrayChunks;
|
||||
int arrayChunksSize; // Size for m_arrayChunks in bytes (DEBUG ONLY)
|
||||
|
||||
int ChunkFlattenOffset;
|
||||
int chunksAllocated;
|
||||
int chunksTotal;
|
||||
|
||||
// Arrays for mesh build
|
||||
ArrayVector3 vertices;
|
||||
ArrayUShort indices;
|
||||
ArrayColor colors;
|
||||
|
||||
//Palette for voxels
|
||||
VoxColor palette[256];
|
||||
|
||||
} VoxArray3D;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
|
||||
// Functions
|
||||
int Vox_LoadFromMemory(unsigned char* pvoxData, unsigned int voxDataSize, VoxArray3D* pvoxarray);
|
||||
void Vox_FreeArrays(VoxArray3D* voxarray);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // VOX_LOADER_H
|
||||
//// end header file /////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Implementation
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef VOX_LOADER_IMPLEMENTATION
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// ArrayUShort helper
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void initArrayUShort(ArrayUShort* a, int initialSize)
|
||||
{
|
||||
a->array = VOX_MALLOC(initialSize * sizeof(unsigned short));
|
||||
a->used = 0;
|
||||
a->size = initialSize;
|
||||
}
|
||||
|
||||
static void insertArrayUShort(ArrayUShort* a, unsigned short element)
|
||||
{
|
||||
if (a->used == a->size)
|
||||
{
|
||||
a->size *= 2;
|
||||
a->array = VOX_REALLOC(a->array, a->size * sizeof(unsigned short));
|
||||
}
|
||||
a->array[a->used++] = element;
|
||||
}
|
||||
|
||||
static void freeArrayUShort(ArrayUShort* a)
|
||||
{
|
||||
VOX_FREE(a->array);
|
||||
a->array = NULL;
|
||||
a->used = a->size = 0;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// ArrayVector3 helper
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void initArrayVector3(ArrayVector3* a, int initialSize)
|
||||
{
|
||||
a->array = VOX_MALLOC(initialSize * sizeof(VoxVector3));
|
||||
a->used = 0;
|
||||
a->size = initialSize;
|
||||
}
|
||||
|
||||
static void insertArrayVector3(ArrayVector3* a, VoxVector3 element)
|
||||
{
|
||||
if (a->used == a->size)
|
||||
{
|
||||
a->size *= 2;
|
||||
a->array = VOX_REALLOC(a->array, a->size * sizeof(VoxVector3));
|
||||
}
|
||||
a->array[a->used++] = element;
|
||||
}
|
||||
|
||||
static void freeArrayVector3(ArrayVector3* a)
|
||||
{
|
||||
VOX_FREE(a->array);
|
||||
a->array = NULL;
|
||||
a->used = a->size = 0;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// ArrayColor helper
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void initArrayColor(ArrayColor* a, int initialSize)
|
||||
{
|
||||
a->array = VOX_MALLOC(initialSize * sizeof(VoxColor));
|
||||
a->used = 0;
|
||||
a->size = initialSize;
|
||||
}
|
||||
|
||||
static void insertArrayColor(ArrayColor* a, VoxColor element)
|
||||
{
|
||||
if (a->used == a->size)
|
||||
{
|
||||
a->size *= 2;
|
||||
a->array = VOX_REALLOC(a->array, a->size * sizeof(VoxColor));
|
||||
}
|
||||
a->array[a->used++] = element;
|
||||
}
|
||||
|
||||
static void freeArrayColor(ArrayColor* a)
|
||||
{
|
||||
VOX_FREE(a->array);
|
||||
a->array = NULL;
|
||||
a->used = a->size = 0;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Vox Loader
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define CHUNKSIZE 16 // chunk size (CHUNKSIZE*CHUNKSIZE*CHUNKSIZE) in voxels
|
||||
#define CHUNKSIZE_OPSHIFT 4 // 1<<4=16 -> Warning depend of CHUNKSIZE
|
||||
#define CHUNK_FLATTENOFFSET_OPSHIFT 8 // Warning depend of CHUNKSIZE
|
||||
|
||||
//
|
||||
// used right handed system and CCW face
|
||||
//
|
||||
// indexes for voxelcoords, per face orientation
|
||||
//
|
||||
|
||||
//# Y
|
||||
//# |
|
||||
//# o----X
|
||||
//# /
|
||||
//# Z 2------------3
|
||||
//# /| /|
|
||||
//# 6------------7 |
|
||||
//# | | | |
|
||||
//# |0 ----------|- 1
|
||||
//# |/ |/
|
||||
//# 4------------5
|
||||
|
||||
//
|
||||
// CCW
|
||||
const int fv[6][4] = {
|
||||
{0, 2, 6, 4 }, //-X
|
||||
{5, 7, 3, 1 }, //+X
|
||||
{0, 4, 5, 1 }, //-y
|
||||
{6, 2, 3, 7 }, //+y
|
||||
{1, 3, 2, 0 }, //-Z
|
||||
{4, 6, 7, 5 } //+Z
|
||||
};
|
||||
|
||||
const VoxVector3 SolidVertex[] = {
|
||||
{0, 0, 0}, //0
|
||||
{1, 0, 0}, //1
|
||||
{0, 1, 0}, //2
|
||||
{1, 1, 0}, //3
|
||||
{0, 0, 1}, //4
|
||||
{1, 0, 1}, //5
|
||||
{0, 1, 1}, //6
|
||||
{1, 1, 1} //7
|
||||
};
|
||||
|
||||
// Allocated VoxArray3D size
|
||||
static void Vox_AllocArray(VoxArray3D* pvoxarray, int _sx, int _sy, int _sz)
|
||||
{
|
||||
int sx = _sx + ((CHUNKSIZE - (_sx % CHUNKSIZE)) % CHUNKSIZE);
|
||||
int sy = _sy + ((CHUNKSIZE - (_sy % CHUNKSIZE)) % CHUNKSIZE);
|
||||
int sz = _sz + ((CHUNKSIZE - (_sz % CHUNKSIZE)) % CHUNKSIZE);
|
||||
|
||||
int chx = sx >> CHUNKSIZE_OPSHIFT; //Chunks Count in X
|
||||
int chy = sy >> CHUNKSIZE_OPSHIFT; //Chunks Count in Y
|
||||
int chz = sz >> CHUNKSIZE_OPSHIFT; //Chunks Count in Z
|
||||
|
||||
//VoxArray3D* parray = (VoxArray3D*)VOX_MALLOC(sizeof(VoxArray3D));
|
||||
pvoxarray->sizeX = sx;
|
||||
pvoxarray->sizeY = sy;
|
||||
pvoxarray->sizeZ = sz;
|
||||
|
||||
pvoxarray->chunksSizeX = chx;
|
||||
pvoxarray->chunksSizeY = chy;
|
||||
pvoxarray->chunksSizeZ = chz;
|
||||
|
||||
pvoxarray->ChunkFlattenOffset = (chy * chz); //m_arrayChunks[(x * (sy*sz)) + (z * sy) + y]
|
||||
|
||||
// Alloc chunks array
|
||||
int size = sizeof(CubeChunk3D) * chx * chy * chz;
|
||||
pvoxarray->m_arrayChunks = VOX_MALLOC(size);
|
||||
pvoxarray->arrayChunksSize = size;
|
||||
|
||||
// Init chunks array
|
||||
size = chx * chy * chz;
|
||||
pvoxarray->chunksTotal = size;
|
||||
pvoxarray->chunksAllocated = 0;
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
pvoxarray->m_arrayChunks[i].m_array = 0;
|
||||
pvoxarray->m_arrayChunks[i].arraySize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Set voxel ID from its position into VoxArray3D
|
||||
static void Vox_SetVoxel(VoxArray3D* pvoxarray, int x, int y, int z, unsigned char id)
|
||||
{
|
||||
// Get chunk from array pos
|
||||
int chX = x >> CHUNKSIZE_OPSHIFT; //x / CHUNKSIZE;
|
||||
int chY = y >> CHUNKSIZE_OPSHIFT; //y / CHUNKSIZE;
|
||||
int chZ = z >> CHUNKSIZE_OPSHIFT; //z / CHUNKSIZE;
|
||||
int offset = (chX * pvoxarray->ChunkFlattenOffset) + (chZ * pvoxarray->chunksSizeY) + chY;
|
||||
|
||||
//if (offset > voxarray->arrayChunksSize)
|
||||
//{
|
||||
// TraceLog(LOG_ERROR, "Out of array");
|
||||
//}
|
||||
|
||||
CubeChunk3D* chunk = &pvoxarray->m_arrayChunks[offset];
|
||||
|
||||
// Set Chunk
|
||||
chX = x - (chX << CHUNKSIZE_OPSHIFT); //x - (bx * CHUNKSIZE);
|
||||
chY = y - (chY << CHUNKSIZE_OPSHIFT); //y - (by * CHUNKSIZE);
|
||||
chZ = z - (chZ << CHUNKSIZE_OPSHIFT); //z - (bz * CHUNKSIZE);
|
||||
|
||||
if (chunk->m_array == 0)
|
||||
{
|
||||
int size = CHUNKSIZE * CHUNKSIZE * CHUNKSIZE;
|
||||
chunk->m_array = VOX_MALLOC(size);
|
||||
chunk->arraySize = size;
|
||||
memset(chunk->m_array, 0, size);
|
||||
|
||||
pvoxarray->chunksAllocated++;
|
||||
}
|
||||
|
||||
offset = (chX << CHUNK_FLATTENOFFSET_OPSHIFT) + (chZ << CHUNKSIZE_OPSHIFT) + chY;
|
||||
|
||||
//if (offset > chunk->arraySize)
|
||||
//{
|
||||
// TraceLog(LOG_ERROR, "Out of array");
|
||||
//}
|
||||
|
||||
chunk->m_array[offset] = id;
|
||||
}
|
||||
|
||||
// Get voxel ID from its position into VoxArray3D
|
||||
static unsigned char Vox_GetVoxel(VoxArray3D* pvoxarray, int x, int y, int z)
|
||||
{
|
||||
if (x < 0 || y < 0 || z < 0) return 0;
|
||||
|
||||
if (x >= pvoxarray->sizeX || y >= pvoxarray->sizeY || z >= pvoxarray->sizeZ) return 0;
|
||||
|
||||
// Get chunk from array pos
|
||||
int chX = x >> CHUNKSIZE_OPSHIFT; //x / CHUNKSIZE;
|
||||
int chY = y >> CHUNKSIZE_OPSHIFT; //y / CHUNKSIZE;
|
||||
int chZ = z >> CHUNKSIZE_OPSHIFT; //z / CHUNKSIZE;
|
||||
int offset = (chX * pvoxarray->ChunkFlattenOffset) + (chZ * pvoxarray->chunksSizeY) + chY;
|
||||
|
||||
//if (offset > voxarray->arrayChunksSize)
|
||||
//{
|
||||
// TraceLog(LOG_ERROR, "Out of array");
|
||||
//}
|
||||
|
||||
CubeChunk3D* chunk = &pvoxarray->m_arrayChunks[offset];
|
||||
|
||||
// Set Chunk
|
||||
chX = x - (chX << CHUNKSIZE_OPSHIFT); //x - (bx * CHUNKSIZE);
|
||||
chY = y - (chY << CHUNKSIZE_OPSHIFT); //y - (by * CHUNKSIZE);
|
||||
chZ = z - (chZ << CHUNKSIZE_OPSHIFT); //z - (bz * CHUNKSIZE);
|
||||
|
||||
if (chunk->m_array == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
offset = (chX << CHUNK_FLATTENOFFSET_OPSHIFT) + (chZ << CHUNKSIZE_OPSHIFT) + chY;
|
||||
|
||||
//if (offset > chunk->arraySize)
|
||||
//{
|
||||
// TraceLog(LOG_ERROR, "Out of array");
|
||||
//}
|
||||
return chunk->m_array[offset];
|
||||
|
||||
}
|
||||
|
||||
// Calc visibles faces from a voxel position
|
||||
static unsigned char Vox_CalcFacesVisible(VoxArray3D* pvoxArray, int cx, int cy, int cz)
|
||||
{
|
||||
unsigned char idXm1 = Vox_GetVoxel(pvoxArray, cx - 1, cy, cz);
|
||||
unsigned char idXp1 = Vox_GetVoxel(pvoxArray, cx + 1, cy, cz);
|
||||
|
||||
unsigned char idYm1 = Vox_GetVoxel(pvoxArray, cx, cy - 1, cz);
|
||||
unsigned char idYp1 = Vox_GetVoxel(pvoxArray, cx, cy + 1, cz);
|
||||
|
||||
unsigned char idZm1 = Vox_GetVoxel(pvoxArray, cx, cy, cz - 1);
|
||||
unsigned char idZp1 = Vox_GetVoxel(pvoxArray, cx, cy, cz + 1);
|
||||
|
||||
unsigned char byVFMask = 0;
|
||||
|
||||
//#-x
|
||||
if (idXm1 == 0) byVFMask |= (1 << 0);
|
||||
|
||||
//#+x
|
||||
if (idXp1 == 0) byVFMask |= (1 << 1);
|
||||
|
||||
//#-y
|
||||
if (idYm1 == 0) byVFMask |= (1 << 2);
|
||||
|
||||
//#+y
|
||||
if (idYp1 == 0) byVFMask |= (1 << 3);
|
||||
|
||||
//#-z
|
||||
if (idZm1 == 0) byVFMask |= (1 << 4);
|
||||
|
||||
//#+z
|
||||
if (idZp1 == 0) byVFMask |= (1 << 5);
|
||||
|
||||
return byVFMask;
|
||||
}
|
||||
|
||||
// Get a vertex position from a voxel's corner
|
||||
static VoxVector3 Vox_GetVertexPosition(int _wcx, int _wcy, int _wcz, int _nNumVertex)
|
||||
{
|
||||
float scale = 0.25;
|
||||
|
||||
VoxVector3 vtx = SolidVertex[_nNumVertex];
|
||||
vtx.x = (vtx.x + _wcx) * scale;
|
||||
vtx.y = (vtx.y + _wcy) * scale;
|
||||
vtx.z = (vtx.z + _wcz) * scale;
|
||||
|
||||
return vtx;
|
||||
}
|
||||
|
||||
// Build a voxel vertices/colors/indices
|
||||
static void Vox_Build_Voxel(VoxArray3D* pvoxArray, int x, int y, int z, int matID)
|
||||
{
|
||||
unsigned char byVFMask = Vox_CalcFacesVisible(pvoxArray, x, y, z);
|
||||
|
||||
if (byVFMask == 0) return;
|
||||
|
||||
int i, j;
|
||||
VoxVector3 vertComputed[8];
|
||||
int bVertexComputed[8];
|
||||
memset(vertComputed, 0, sizeof(vertComputed));
|
||||
memset(bVertexComputed, 0, sizeof(bVertexComputed));
|
||||
|
||||
//For each Cube's faces
|
||||
for (i = 0; i < 6; i++) // 6 faces
|
||||
{
|
||||
if ((byVFMask & (1 << i)) != 0) //If face is visible
|
||||
{
|
||||
for (j = 0; j < 4; j++) // 4 corners
|
||||
{
|
||||
int nNumVertex = fv[i][j]; //Face,Corner
|
||||
if (bVertexComputed[nNumVertex] == 0) //if never calc
|
||||
{
|
||||
bVertexComputed[nNumVertex] = 1;
|
||||
vertComputed[nNumVertex] = Vox_GetVertexPosition(x, y, z, nNumVertex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Add face
|
||||
for (i = 0; i < 6; i++)// 6 faces
|
||||
{
|
||||
if ((byVFMask & (1 << i)) == 0)
|
||||
continue; //Face invisible
|
||||
|
||||
int v0 = fv[i][0]; //Face, Corner
|
||||
int v1 = fv[i][1]; //Face, Corner
|
||||
int v2 = fv[i][2]; //Face, Corner
|
||||
int v3 = fv[i][3]; //Face, Corner
|
||||
|
||||
//Arrays
|
||||
int idx = pvoxArray->vertices.used;
|
||||
insertArrayVector3(&pvoxArray->vertices, vertComputed[v0]);
|
||||
insertArrayVector3(&pvoxArray->vertices, vertComputed[v1]);
|
||||
insertArrayVector3(&pvoxArray->vertices, vertComputed[v2]);
|
||||
insertArrayVector3(&pvoxArray->vertices, vertComputed[v3]);
|
||||
|
||||
VoxColor col = pvoxArray->palette[matID];
|
||||
|
||||
insertArrayColor(&pvoxArray->colors, col);
|
||||
insertArrayColor(&pvoxArray->colors, col);
|
||||
insertArrayColor(&pvoxArray->colors, col);
|
||||
insertArrayColor(&pvoxArray->colors, col);
|
||||
|
||||
|
||||
//v0 - v1 - v2, v0 - v2 - v3
|
||||
insertArrayUShort(&pvoxArray->indices, idx + 0);
|
||||
insertArrayUShort(&pvoxArray->indices, idx + 2);
|
||||
insertArrayUShort(&pvoxArray->indices, idx + 1);
|
||||
|
||||
insertArrayUShort(&pvoxArray->indices, idx + 0);
|
||||
insertArrayUShort(&pvoxArray->indices, idx + 3);
|
||||
insertArrayUShort(&pvoxArray->indices, idx + 2);
|
||||
}
|
||||
}
|
||||
|
||||
// MagicaVoxel *.vox file format Loader
|
||||
int Vox_LoadFromMemory(unsigned char* pvoxData, unsigned int voxDataSize, VoxArray3D* pvoxarray)
|
||||
{
|
||||
//////////////////////////////////////////////////
|
||||
//Read VOX file
|
||||
//4 bytes: magic number ('V' 'O' 'X' 'space' )
|
||||
//4 bytes: version number (current version is 150 )
|
||||
|
||||
unsigned long signature;
|
||||
|
||||
unsigned char* fileData = pvoxData;
|
||||
|
||||
unsigned char* fileDataPtr = fileData;
|
||||
unsigned char* endfileDataPtr = fileData + voxDataSize;
|
||||
|
||||
signature = *((unsigned long *)fileDataPtr);
|
||||
fileDataPtr += sizeof(unsigned long);
|
||||
|
||||
if (signature != 0x20584F56) //56 4F 58 20
|
||||
{
|
||||
return VOX_ERROR_INVALID_FORMAT; //"Not an MagicaVoxel File format"
|
||||
}
|
||||
|
||||
unsigned long version;
|
||||
|
||||
version = *((unsigned long*)fileDataPtr);
|
||||
fileDataPtr += sizeof(unsigned long);
|
||||
|
||||
if (version < 150)
|
||||
{
|
||||
return VOX_ERROR_FILE_VERSION_TOO_OLD; //"MagicaVoxel version too old"
|
||||
}
|
||||
|
||||
|
||||
// header
|
||||
//4 bytes: chunk id
|
||||
//4 bytes: size of chunk contents (n)
|
||||
//4 bytes: total size of children chunks(m)
|
||||
|
||||
//// chunk content
|
||||
//n bytes: chunk contents
|
||||
|
||||
//// children chunks : m bytes
|
||||
//{ child chunk 0 }
|
||||
//{ child chunk 1 }
|
||||
unsigned long sizeX, sizeY, sizeZ;
|
||||
sizeX = sizeY = sizeZ = 0;
|
||||
unsigned long numVoxels = 0;
|
||||
|
||||
while (fileDataPtr < endfileDataPtr)
|
||||
{
|
||||
char szChunkName[5];
|
||||
memcpy(szChunkName, fileDataPtr, 4);
|
||||
szChunkName[4] = 0;
|
||||
fileDataPtr += 4;
|
||||
|
||||
unsigned long chunkSize = *((unsigned long*)fileDataPtr);
|
||||
fileDataPtr += sizeof(unsigned long);
|
||||
|
||||
//unsigned long chunkTotalChildSize = *((unsigned long*)fileDataPtr);
|
||||
fileDataPtr += sizeof(unsigned long);
|
||||
|
||||
if (strcmp(szChunkName, "SIZE") == 0)
|
||||
{
|
||||
//(4 bytes x 3 : x, y, z )
|
||||
sizeX = *((unsigned long*)fileDataPtr);
|
||||
fileDataPtr += sizeof(unsigned long);
|
||||
|
||||
sizeY = *((unsigned long*)fileDataPtr);
|
||||
fileDataPtr += sizeof(unsigned long);
|
||||
|
||||
sizeZ = *((unsigned long*)fileDataPtr);
|
||||
fileDataPtr += sizeof(unsigned long);
|
||||
|
||||
//Alloc vox array
|
||||
Vox_AllocArray(pvoxarray, sizeX, sizeZ, sizeY); //Reverse Y<>Z for left to right handed system
|
||||
}
|
||||
else if (strcmp(szChunkName, "XYZI") == 0)
|
||||
{
|
||||
unsigned char vx, vy, vz, vi;
|
||||
|
||||
//(numVoxels : 4 bytes )
|
||||
//(each voxel: 1 byte x 4 : x, y, z, colorIndex ) x numVoxels
|
||||
numVoxels = *((unsigned long*)fileDataPtr);
|
||||
fileDataPtr += sizeof(unsigned long);
|
||||
|
||||
while (numVoxels > 0)
|
||||
{
|
||||
vx = *((unsigned char*)fileDataPtr++);
|
||||
vy = *((unsigned char*)fileDataPtr++);
|
||||
vz = *((unsigned char*)fileDataPtr++);
|
||||
vi = *((unsigned char*)fileDataPtr++);
|
||||
|
||||
Vox_SetVoxel(pvoxarray, vx, vz, pvoxarray->sizeZ-vy-1, vi); //Reverse Y<>Z for left to right handed system
|
||||
|
||||
numVoxels--;
|
||||
}
|
||||
}
|
||||
else if (strcmp(szChunkName, "RGBA") == 0)
|
||||
{
|
||||
VoxColor col;
|
||||
|
||||
//(each pixel: 1 byte x 4 : r, g, b, a ) x 256
|
||||
for (int i = 0; i < 256 - 1; i++)
|
||||
{
|
||||
col.r = *((unsigned char*)fileDataPtr++);
|
||||
col.g = *((unsigned char*)fileDataPtr++);
|
||||
col.b = *((unsigned char*)fileDataPtr++);
|
||||
col.a = *((unsigned char*)fileDataPtr++);
|
||||
|
||||
pvoxarray->palette[i + 1] = col;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
fileDataPtr += chunkSize;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
// Building Mesh
|
||||
// TODO compute globals indices array
|
||||
|
||||
// Init Arrays
|
||||
initArrayVector3(&pvoxarray->vertices, 3 * 1024);
|
||||
initArrayUShort(&pvoxarray->indices, 3 * 1024);
|
||||
initArrayColor(&pvoxarray->colors, 3 * 1024);
|
||||
|
||||
// Create vertices and indices buffers
|
||||
int x, y, z;
|
||||
|
||||
for (x = 0; x <= pvoxarray->sizeX; x++)
|
||||
{
|
||||
for (z = 0; z <= pvoxarray->sizeZ; z++)
|
||||
{
|
||||
for (y = 0; y <= pvoxarray->sizeY; y++)
|
||||
{
|
||||
unsigned char matID = Vox_GetVoxel(pvoxarray, x, y, z);
|
||||
if (matID != 0)
|
||||
Vox_Build_Voxel(pvoxarray, x, y, z, matID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return VOX_SUCCESS;
|
||||
}
|
||||
|
||||
void Vox_FreeArrays(VoxArray3D* voxarray)
|
||||
{
|
||||
// Free chunks
|
||||
if (voxarray->m_arrayChunks != 0)
|
||||
{
|
||||
for (int i = 0; i < voxarray->chunksTotal; i++)
|
||||
{
|
||||
CubeChunk3D* chunk = &voxarray->m_arrayChunks[i];
|
||||
if (chunk->m_array != 0)
|
||||
{
|
||||
chunk->arraySize = 0;
|
||||
VOX_FREE(chunk->m_array);
|
||||
}
|
||||
}
|
||||
|
||||
VOX_FREE(voxarray->m_arrayChunks);
|
||||
voxarray->m_arrayChunks = 0;
|
||||
voxarray->arrayChunksSize = 0;
|
||||
|
||||
voxarray->chunksSizeX = voxarray->chunksSizeY = voxarray->chunksSizeZ = 0;
|
||||
voxarray->chunksTotal = 0;
|
||||
voxarray->chunksAllocated = 0;
|
||||
voxarray->ChunkFlattenOffset = 0;
|
||||
voxarray->sizeX = voxarray->sizeY = voxarray->sizeZ = 0;
|
||||
}
|
||||
|
||||
// Free arrays
|
||||
freeArrayVector3(&voxarray->vertices);
|
||||
freeArrayUShort(&voxarray->indices);
|
||||
freeArrayColor(&voxarray->colors);
|
||||
}
|
||||
|
||||
#endif //VOX_LOADER_IMPLEMENTATION
|
|
@ -1,4 +0,0 @@
|
|||
// The implementation of mini_al needs to #include windows.h which means it needs to go into
|
||||
// it's own translation unit. Not doing this will cause conflicts with CloseWindow(), etc.
|
||||
#define MAL_IMPLEMENTATION
|
||||
#include "external/miniaudio.h"
|
644
raylib/raudio.c
644
raylib/raudio.c
File diff suppressed because it is too large
Load diff
|
@ -78,49 +78,42 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
// Wave type, defines audio wave data
|
||||
// Wave, audio wave data
|
||||
typedef struct Wave {
|
||||
unsigned int sampleCount; // Total number of samples
|
||||
unsigned int frameCount; // Total number of frames (considering channels)
|
||||
unsigned int sampleRate; // Frequency (samples per second)
|
||||
unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported)
|
||||
unsigned int channels; // Number of channels (1-mono, 2-stereo)
|
||||
unsigned int channels; // Number of channels (1-mono, 2-stereo, ...)
|
||||
void *data; // Buffer data pointer
|
||||
} Wave;
|
||||
|
||||
typedef struct rAudioBuffer rAudioBuffer;
|
||||
|
||||
// Audio stream type
|
||||
// NOTE: Useful to create custom audio streams not bound to a specific file
|
||||
// AudioStream, custom audio stream
|
||||
typedef struct AudioStream {
|
||||
rAudioBuffer *buffer; // Pointer to internal data used by the audio system
|
||||
|
||||
unsigned int sampleRate; // Frequency (samples per second)
|
||||
unsigned int sampleSize; // Bit depth (bits per sample): 8, 16, 32 (24 not supported)
|
||||
unsigned int channels; // Number of channels (1-mono, 2-stereo)
|
||||
|
||||
rAudioBuffer *buffer; // Pointer to internal data used by the audio system
|
||||
unsigned int channels; // Number of channels (1-mono, 2-stereo, ...)
|
||||
} AudioStream;
|
||||
|
||||
// Sound source type
|
||||
// Sound
|
||||
typedef struct Sound {
|
||||
unsigned int sampleCount; // Total number of samples
|
||||
AudioStream stream; // Audio stream
|
||||
unsigned int frameCount; // Total number of frames (considering channels)
|
||||
} Sound;
|
||||
|
||||
// Music stream type (audio file streaming from memory)
|
||||
// NOTE: Anything longer than ~10 seconds should be streamed
|
||||
// Music, audio stream, anything longer than ~10 seconds should be streamed
|
||||
typedef struct Music {
|
||||
AudioStream stream; // Audio stream
|
||||
unsigned int frameCount; // Total number of frames (considering channels)
|
||||
bool looping; // Music looping enable
|
||||
|
||||
int ctxType; // Type of music context (audio filetype)
|
||||
void *ctxData; // Audio context data, depends on type
|
||||
|
||||
bool looping; // Music looping enable
|
||||
unsigned int sampleCount; // Total number of samples
|
||||
|
||||
AudioStream stream; // Audio stream
|
||||
} Music;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -130,6 +123,10 @@ extern "C" { // Prevents name mangling of functions
|
|||
// Module Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
|
||||
// Audio device management functions
|
||||
void InitAudioDevice(void); // Initialize audio device and context
|
||||
void CloseAudioDevice(void); // Close the audio device and context
|
||||
|
@ -174,15 +171,16 @@ void UpdateMusicStream(Music music); // Updates buffe
|
|||
void StopMusicStream(Music music); // Stop music playing
|
||||
void PauseMusicStream(Music music); // Pause music playing
|
||||
void ResumeMusicStream(Music music); // Resume playing paused music
|
||||
void SeekMusicStream(Music music, float position); // Seek music to a position (in seconds)
|
||||
void SetMusicVolume(Music music, float volume); // Set volume for music (1.0 is max level)
|
||||
void SetMusicPitch(Music music, float pitch); // Set pitch for a music (1.0 is base level)
|
||||
float GetMusicTimeLength(Music music); // Get music time length (in seconds)
|
||||
float GetMusicTimePlayed(Music music); // Get current music time played (in seconds)
|
||||
|
||||
// AudioStream management functions
|
||||
AudioStream InitAudioStream(unsigned int sampleRate, unsigned int sampleSize, unsigned int channels); // Init audio stream (to stream raw audio pcm data)
|
||||
AudioStream LoadAudioStream(unsigned int sampleRate, unsigned int sampleSize, unsigned int channels); // Load audio stream (to stream raw audio pcm data)
|
||||
void UpdateAudioStream(AudioStream stream, const void *data, int samplesCount); // Update audio stream buffers with data
|
||||
void CloseAudioStream(AudioStream stream); // Close audio stream and free memory
|
||||
void UnloadAudioStream(AudioStream stream); // Unload audio stream and free memory
|
||||
bool IsAudioStreamProcessed(AudioStream stream); // Check if any audio stream buffers requires refill
|
||||
void PlayAudioStream(AudioStream stream); // Play audio stream
|
||||
void PauseAudioStream(AudioStream stream); // Pause audio stream
|
||||
|
|
1038
raylib/raylib.h
1038
raylib/raylib.h
File diff suppressed because it is too large
Load diff
953
raylib/raymath.h
953
raylib/raymath.h
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib.camera - Camera system with multiple modes support
|
||||
* rcamera - Basic camera system for multiple camera modes
|
||||
*
|
||||
* NOTE: Memory footprint of this library is aproximately 52 bytes (global variables)
|
||||
*
|
||||
|
@ -41,8 +41,8 @@
|
|||
*
|
||||
**********************************************************************************************/
|
||||
|
||||
#ifndef CAMERA_H
|
||||
#define CAMERA_H
|
||||
#ifndef RCAMERA_H
|
||||
#define RCAMERA_H
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
|
@ -94,10 +94,6 @@
|
|||
} CameraProjection;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -106,6 +102,11 @@ extern "C" { // Prevents name mangling of functions
|
|||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
|
||||
#if defined(CAMERA_STANDALONE)
|
||||
void SetCameraMode(Camera camera, int mode); // Set camera mode (multiple camera modes available)
|
||||
void UpdateCamera(Camera *camera); // Update camera position for selected mode
|
||||
|
@ -203,6 +204,7 @@ typedef struct {
|
|||
float targetDistance; // Camera distance from position to target
|
||||
float playerEyesPosition; // Player eyes position from ground (in meters)
|
||||
Vector2 angle; // Camera angle in plane XZ
|
||||
Vector2 previousMousePosition; // Previous mouse position
|
||||
|
||||
// Camera movement control keys
|
||||
int moveControl[6]; // Move controls (CAMERA_FIRST_PERSON)
|
||||
|
@ -219,6 +221,7 @@ static CameraData CAMERA = { // Global CAMERA state context
|
|||
.targetDistance = 0,
|
||||
.playerEyesPosition = 1.85f,
|
||||
.angle = { 0 },
|
||||
.previousMousePosition = { 0 },
|
||||
.moveControl = { 'W', 'S', 'D', 'A', 'E', 'Q' },
|
||||
.smoothZoomControl = 341, // raylib: KEY_LEFT_CONTROL
|
||||
.altControl = 342, // raylib: KEY_LEFT_ALT
|
||||
|
@ -262,6 +265,8 @@ void SetCameraMode(Camera camera, int mode)
|
|||
|
||||
CAMERA.playerEyesPosition = camera.position.y; // Init player eyes position to camera Y position
|
||||
|
||||
CAMERA.previousMousePosition = GetMousePosition(); // Init mouse position
|
||||
|
||||
// Lock cursor for first person and third person cameras
|
||||
if ((mode == CAMERA_FIRST_PERSON) || (mode == CAMERA_THIRD_PERSON)) DisableCursor();
|
||||
else EnableCursor();
|
||||
|
@ -274,11 +279,9 @@ void SetCameraMode(Camera camera, int mode)
|
|||
// System: EnableCursor(), DisableCursor()
|
||||
// Mouse: IsMouseButtonDown(), GetMousePosition(), GetMouseWheelMove()
|
||||
// Keys: IsKeyDown()
|
||||
// TODO: Port to quaternion-based camera (?)
|
||||
void UpdateCamera(Camera *camera)
|
||||
{
|
||||
static int swingCounter = 0; // Used for 1st person swinging movement
|
||||
static Vector2 previousMousePosition = { 0.0f, 0.0f };
|
||||
|
||||
// TODO: Compute CAMERA.targetDistance and CAMERA.angle here (?)
|
||||
|
||||
|
@ -301,10 +304,10 @@ void UpdateCamera(Camera *camera)
|
|||
|
||||
if (CAMERA.mode != CAMERA_CUSTOM)
|
||||
{
|
||||
mousePositionDelta.x = mousePosition.x - previousMousePosition.x;
|
||||
mousePositionDelta.y = mousePosition.y - previousMousePosition.y;
|
||||
mousePositionDelta.x = mousePosition.x - CAMERA.previousMousePosition.x;
|
||||
mousePositionDelta.y = mousePosition.y - CAMERA.previousMousePosition.y;
|
||||
|
||||
previousMousePosition = mousePosition;
|
||||
CAMERA.previousMousePosition = mousePosition;
|
||||
}
|
||||
|
||||
// Support for multiple automatic camera modes
|
||||
|
@ -435,14 +438,57 @@ void UpdateCamera(Camera *camera)
|
|||
if (CAMERA.angle.y > CAMERA_FIRST_PERSON_MIN_CLAMP*DEG2RAD) CAMERA.angle.y = CAMERA_FIRST_PERSON_MIN_CLAMP*DEG2RAD;
|
||||
else if (CAMERA.angle.y < CAMERA_FIRST_PERSON_MAX_CLAMP*DEG2RAD) CAMERA.angle.y = CAMERA_FIRST_PERSON_MAX_CLAMP*DEG2RAD;
|
||||
|
||||
// Recalculate camera target considering translation and rotation
|
||||
Matrix translation = MatrixTranslate(0, 0, (CAMERA.targetDistance/CAMERA_FREE_PANNING_DIVIDER));
|
||||
Matrix rotation = MatrixRotateXYZ((Vector3){ PI*2 - CAMERA.angle.y, PI*2 - CAMERA.angle.x, 0 });
|
||||
Matrix transform = MatrixMultiply(translation, rotation);
|
||||
// Calculate translation matrix
|
||||
Matrix matTranslation = { 1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, (CAMERA.targetDistance/CAMERA_FREE_PANNING_DIVIDER),
|
||||
0.0f, 0.0f, 0.0f, 1.0f };
|
||||
|
||||
camera->target.x = camera->position.x - transform.m12;
|
||||
camera->target.y = camera->position.y - transform.m13;
|
||||
camera->target.z = camera->position.z - transform.m14;
|
||||
// Calculate rotation matrix
|
||||
Matrix matRotation = { 1.0f, 0.0f, 0.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f };
|
||||
|
||||
float cosz = cosf(0.0f);
|
||||
float sinz = sinf(0.0f);
|
||||
float cosy = cosf(-(PI*2 - CAMERA.angle.x));
|
||||
float siny = sinf(-(PI*2 - CAMERA.angle.x));
|
||||
float cosx = cosf(-(PI*2 - CAMERA.angle.y));
|
||||
float sinx = sinf(-(PI*2 - CAMERA.angle.y));
|
||||
|
||||
matRotation.m0 = cosz*cosy;
|
||||
matRotation.m4 = (cosz*siny*sinx) - (sinz*cosx);
|
||||
matRotation.m8 = (cosz*siny*cosx) + (sinz*sinx);
|
||||
matRotation.m1 = sinz*cosy;
|
||||
matRotation.m5 = (sinz*siny*sinx) + (cosz*cosx);
|
||||
matRotation.m9 = (sinz*siny*cosx) - (cosz*sinx);
|
||||
matRotation.m2 = -siny;
|
||||
matRotation.m6 = cosy*sinx;
|
||||
matRotation.m10= cosy*cosx;
|
||||
|
||||
// Multiply translation and rotation matrices
|
||||
Matrix matTransform = { 0 };
|
||||
matTransform.m0 = matTranslation.m0*matRotation.m0 + matTranslation.m1*matRotation.m4 + matTranslation.m2*matRotation.m8 + matTranslation.m3*matRotation.m12;
|
||||
matTransform.m1 = matTranslation.m0*matRotation.m1 + matTranslation.m1*matRotation.m5 + matTranslation.m2*matRotation.m9 + matTranslation.m3*matRotation.m13;
|
||||
matTransform.m2 = matTranslation.m0*matRotation.m2 + matTranslation.m1*matRotation.m6 + matTranslation.m2*matRotation.m10 + matTranslation.m3*matRotation.m14;
|
||||
matTransform.m3 = matTranslation.m0*matRotation.m3 + matTranslation.m1*matRotation.m7 + matTranslation.m2*matRotation.m11 + matTranslation.m3*matRotation.m15;
|
||||
matTransform.m4 = matTranslation.m4*matRotation.m0 + matTranslation.m5*matRotation.m4 + matTranslation.m6*matRotation.m8 + matTranslation.m7*matRotation.m12;
|
||||
matTransform.m5 = matTranslation.m4*matRotation.m1 + matTranslation.m5*matRotation.m5 + matTranslation.m6*matRotation.m9 + matTranslation.m7*matRotation.m13;
|
||||
matTransform.m6 = matTranslation.m4*matRotation.m2 + matTranslation.m5*matRotation.m6 + matTranslation.m6*matRotation.m10 + matTranslation.m7*matRotation.m14;
|
||||
matTransform.m7 = matTranslation.m4*matRotation.m3 + matTranslation.m5*matRotation.m7 + matTranslation.m6*matRotation.m11 + matTranslation.m7*matRotation.m15;
|
||||
matTransform.m8 = matTranslation.m8*matRotation.m0 + matTranslation.m9*matRotation.m4 + matTranslation.m10*matRotation.m8 + matTranslation.m11*matRotation.m12;
|
||||
matTransform.m9 = matTranslation.m8*matRotation.m1 + matTranslation.m9*matRotation.m5 + matTranslation.m10*matRotation.m9 + matTranslation.m11*matRotation.m13;
|
||||
matTransform.m10 = matTranslation.m8*matRotation.m2 + matTranslation.m9*matRotation.m6 + matTranslation.m10*matRotation.m10 + matTranslation.m11*matRotation.m14;
|
||||
matTransform.m11 = matTranslation.m8*matRotation.m3 + matTranslation.m9*matRotation.m7 + matTranslation.m10*matRotation.m11 + matTranslation.m11*matRotation.m15;
|
||||
matTransform.m12 = matTranslation.m12*matRotation.m0 + matTranslation.m13*matRotation.m4 + matTranslation.m14*matRotation.m8 + matTranslation.m15*matRotation.m12;
|
||||
matTransform.m13 = matTranslation.m12*matRotation.m1 + matTranslation.m13*matRotation.m5 + matTranslation.m14*matRotation.m9 + matTranslation.m15*matRotation.m13;
|
||||
matTransform.m14 = matTranslation.m12*matRotation.m2 + matTranslation.m13*matRotation.m6 + matTranslation.m14*matRotation.m10 + matTranslation.m15*matRotation.m14;
|
||||
matTransform.m15 = matTranslation.m12*matRotation.m3 + matTranslation.m13*matRotation.m7 + matTranslation.m14*matRotation.m11 + matTranslation.m15*matRotation.m15;
|
||||
|
||||
camera->target.x = camera->position.x - matTransform.m12;
|
||||
camera->target.y = camera->position.y - matTransform.m13;
|
||||
camera->target.z = camera->position.z - matTransform.m14;
|
||||
|
||||
// If movement detected (some key pressed), increase swinging
|
||||
for (int i = 0; i < 6; i++) if (direction[i]) { swingCounter++; break; }
|
||||
|
@ -485,7 +531,6 @@ void UpdateCamera(Camera *camera)
|
|||
// Camera distance clamp
|
||||
if (CAMERA.targetDistance < CAMERA_THIRD_PERSON_DISTANCE_CLAMP) CAMERA.targetDistance = CAMERA_THIRD_PERSON_DISTANCE_CLAMP;
|
||||
|
||||
// TODO: It seems camera->position is not correctly updated or some rounding issue makes the camera move straight to camera->target...
|
||||
camera->position.x = sinf(CAMERA.angle.x)*CAMERA.targetDistance*cosf(CAMERA.angle.y) + camera->target.x;
|
||||
|
||||
if (CAMERA.angle.y <= 0.0f) camera->position.y = sinf(CAMERA.angle.y)*CAMERA.targetDistance*sinf(CAMERA.angle.y) + camera->target.y;
|
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
|||
/**********************************************************************************************
|
||||
*
|
||||
* raylib.gestures - Gestures system, gestures processing based on input events (touch/mouse)
|
||||
* rgestures - Gestures system, gestures processing based on input events (touch/mouse)
|
||||
*
|
||||
* NOTE: Memory footprint of this library is aproximately 128 bytes (global variables)
|
||||
*
|
||||
|
@ -43,8 +43,8 @@
|
|||
*
|
||||
**********************************************************************************************/
|
||||
|
||||
#ifndef GESTURES_H
|
||||
#define GESTURES_H
|
||||
#ifndef RGESTURES_H
|
||||
#define RGESTURES_H
|
||||
|
||||
#ifndef PI
|
||||
#define PI 3.14159265358979323846
|
||||
|
@ -53,27 +53,33 @@
|
|||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
//...
|
||||
#ifndef MAX_TOUCH_POINTS
|
||||
#define MAX_TOUCH_POINTS 8 // Maximum number of touch points supported
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
// NOTE: Below types are required for GESTURES_STANDALONE usage
|
||||
//----------------------------------------------------------------------------------
|
||||
#if defined(GESTURES_STANDALONE)
|
||||
#ifndef __cplusplus
|
||||
// Boolean type
|
||||
typedef enum { false, true } bool;
|
||||
#endif
|
||||
// Boolean type
|
||||
#if defined(__STDC__) && __STDC_VERSION__ >= 199901L
|
||||
#include <stdbool.h>
|
||||
#elif !defined(__cplusplus) && !defined(bool) && !defined(RL_BOOL_TYPE)
|
||||
typedef enum bool { false, true } bool;
|
||||
#endif
|
||||
|
||||
// Vector2 type
|
||||
typedef struct Vector2 {
|
||||
#if !defined(RL_VECTOR2_TYPE)
|
||||
// Vector2 type
|
||||
typedef struct Vector2 {
|
||||
float x;
|
||||
float y;
|
||||
} Vector2;
|
||||
} Vector2;
|
||||
#endif
|
||||
|
||||
// Gestures type
|
||||
// NOTE: It could be used as flags to enable only some gestures
|
||||
typedef enum {
|
||||
#if defined(GESTURES_STANDALONE)
|
||||
// Gestures type
|
||||
// NOTE: It could be used as flags to enable only some gestures
|
||||
typedef enum {
|
||||
GESTURE_NONE = 0,
|
||||
GESTURE_TAP = 1,
|
||||
GESTURE_DOUBLETAP = 2,
|
||||
|
@ -85,24 +91,24 @@
|
|||
GESTURE_SWIPE_DOWN = 128,
|
||||
GESTURE_PINCH_IN = 256,
|
||||
GESTURE_PINCH_OUT = 512
|
||||
} Gestures;
|
||||
} Gesture;
|
||||
#endif
|
||||
|
||||
typedef enum { TOUCH_UP, TOUCH_DOWN, TOUCH_MOVE } TouchAction;
|
||||
typedef enum {
|
||||
TOUCH_ACTION_UP = 0,
|
||||
TOUCH_ACTION_DOWN,
|
||||
TOUCH_ACTION_MOVE,
|
||||
TOUCH_ACTION_CANCEL
|
||||
} TouchAction;
|
||||
|
||||
// Gesture event
|
||||
// NOTE: MAX_TOUCH_POINTS fixed to 4
|
||||
typedef struct {
|
||||
int touchAction;
|
||||
int pointCount;
|
||||
int pointerId[4];
|
||||
Vector2 position[4];
|
||||
int pointId[MAX_TOUCH_POINTS];
|
||||
Vector2 position[MAX_TOUCH_POINTS];
|
||||
} GestureEvent;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -111,6 +117,11 @@ extern "C" { // Prevents name mangling of functions
|
|||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
|
||||
void ProcessGestureEvent(GestureEvent event); // Process gesture event and translate it into gestures
|
||||
void UpdateGestures(void); // Update gestures detected (must be called every frame)
|
||||
|
||||
|
@ -118,7 +129,7 @@ void UpdateGestures(void); // Update gestures detec
|
|||
void SetGesturesEnabled(unsigned int flags); // Enable a set of gestures using flags
|
||||
bool IsGestureDetected(int gesture); // Check if a gesture have been detected
|
||||
int GetGestureDetected(void); // Get latest detected gesture
|
||||
int GetTouchPointsCount(void); // Get touch points count
|
||||
|
||||
float GetGestureHoldDuration(void); // Get gesture hold time in milliseconds
|
||||
Vector2 GetGestureDragVector(void); // Get gesture drag vector
|
||||
float GetGestureDragAngle(void); // Get gesture drag angle
|
||||
|
@ -141,9 +152,15 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang
|
|||
#if defined(GESTURES_IMPLEMENTATION)
|
||||
|
||||
#if defined(_WIN32)
|
||||
#if defined(__cplusplus)
|
||||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
// Functions required to query time on Windows
|
||||
int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount);
|
||||
int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency);
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
#elif defined(__linux__)
|
||||
#if _POSIX_C_SOURCE < 199309L
|
||||
#undef _POSIX_C_SOURCE
|
||||
|
@ -187,7 +204,7 @@ typedef struct {
|
|||
Vector2 downDragPosition; // Touch drag position
|
||||
Vector2 moveDownPositionA; // First touch down position on move
|
||||
Vector2 moveDownPositionB; // Second touch down position on move
|
||||
int tapCounter; // TAP counter (one tap implies TOUCH_DOWN and TOUCH_UP actions)
|
||||
int tapCounter; // TAP counter (one tap implies TOUCH_ACTION_DOWN and TOUCH_ACTION_UP actions)
|
||||
} Touch;
|
||||
struct {
|
||||
bool resetRequired; // HOLD reset to get first touch point again
|
||||
|
@ -222,12 +239,9 @@ static GesturesData GESTURES = {
|
|||
//----------------------------------------------------------------------------------
|
||||
// Module specific Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
#if defined(GESTURES_STANDALONE)
|
||||
// Some required math functions provided by raymath.h
|
||||
static float Vector2Angle(Vector2 initialPosition, Vector2 finalPosition);
|
||||
static float Vector2Distance(Vector2 v1, Vector2 v2);
|
||||
#endif
|
||||
static double GetCurrentTime(void);
|
||||
static float rgVector2Angle(Vector2 initialPosition, Vector2 finalPosition);
|
||||
static float rgVector2Distance(Vector2 v1, Vector2 v2);
|
||||
static double rgGetCurrentTime(void);
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition
|
||||
|
@ -252,14 +266,14 @@ void ProcessGestureEvent(GestureEvent event)
|
|||
// Reset required variables
|
||||
GESTURES.Touch.pointCount = event.pointCount; // Required on UpdateGestures()
|
||||
|
||||
if (GESTURES.Touch.pointCount < 2)
|
||||
if (GESTURES.Touch.pointCount == 1) // One touch point
|
||||
{
|
||||
if (event.touchAction == TOUCH_DOWN)
|
||||
if (event.touchAction == TOUCH_ACTION_DOWN)
|
||||
{
|
||||
GESTURES.Touch.tapCounter++; // Tap counter
|
||||
|
||||
// Detect GESTURE_DOUBLE_TAP
|
||||
if ((GESTURES.current == GESTURE_NONE) && (GESTURES.Touch.tapCounter >= 2) && ((GetCurrentTime() - GESTURES.Touch.eventTime) < TAP_TIMEOUT) && (Vector2Distance(GESTURES.Touch.downPositionA, event.position[0]) < DOUBLETAP_RANGE))
|
||||
if ((GESTURES.current == GESTURE_NONE) && (GESTURES.Touch.tapCounter >= 2) && ((rgGetCurrentTime() - GESTURES.Touch.eventTime) < TAP_TIMEOUT) && (rgVector2Distance(GESTURES.Touch.downPositionA, event.position[0]) < DOUBLETAP_RANGE))
|
||||
{
|
||||
GESTURES.current = GESTURE_DOUBLETAP;
|
||||
GESTURES.Touch.tapCounter = 0;
|
||||
|
@ -274,27 +288,27 @@ void ProcessGestureEvent(GestureEvent event)
|
|||
GESTURES.Touch.downDragPosition = event.position[0];
|
||||
|
||||
GESTURES.Touch.upPosition = GESTURES.Touch.downPositionA;
|
||||
GESTURES.Touch.eventTime = GetCurrentTime();
|
||||
GESTURES.Touch.eventTime = rgGetCurrentTime();
|
||||
|
||||
GESTURES.Touch.firstId = event.pointerId[0];
|
||||
GESTURES.Touch.firstId = event.pointId[0];
|
||||
|
||||
GESTURES.Drag.vector = (Vector2){ 0.0f, 0.0f };
|
||||
}
|
||||
else if (event.touchAction == TOUCH_UP)
|
||||
else if (event.touchAction == TOUCH_ACTION_UP)
|
||||
{
|
||||
if (GESTURES.current == GESTURE_DRAG) GESTURES.Touch.upPosition = event.position[0];
|
||||
|
||||
// NOTE: GESTURES.Drag.intensity dependend on the resolution of the screen
|
||||
GESTURES.Drag.distance = Vector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition);
|
||||
GESTURES.Drag.intensity = GESTURES.Drag.distance/(float)((GetCurrentTime() - GESTURES.Swipe.timeDuration));
|
||||
GESTURES.Drag.distance = rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition);
|
||||
GESTURES.Drag.intensity = GESTURES.Drag.distance/(float)((rgGetCurrentTime() - GESTURES.Swipe.timeDuration));
|
||||
|
||||
GESTURES.Swipe.start = false;
|
||||
|
||||
// Detect GESTURE_SWIPE
|
||||
if ((GESTURES.Drag.intensity > FORCE_TO_SWIPE) && (GESTURES.Touch.firstId == event.pointerId[0]))
|
||||
if ((GESTURES.Drag.intensity > FORCE_TO_SWIPE) && (GESTURES.Touch.firstId == event.pointId[0]))
|
||||
{
|
||||
// NOTE: Angle should be inverted in Y
|
||||
GESTURES.Drag.angle = 360.0f - Vector2Angle(GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition);
|
||||
GESTURES.Drag.angle = 360.0f - rgVector2Angle(GESTURES.Touch.downPositionA, GESTURES.Touch.upPosition);
|
||||
|
||||
if ((GESTURES.Drag.angle < 30) || (GESTURES.Drag.angle > 330)) GESTURES.current = GESTURE_SWIPE_RIGHT; // Right
|
||||
else if ((GESTURES.Drag.angle > 30) && (GESTURES.Drag.angle < 120)) GESTURES.current = GESTURE_SWIPE_UP; // Up
|
||||
|
@ -314,13 +328,13 @@ void ProcessGestureEvent(GestureEvent event)
|
|||
GESTURES.Touch.downDragPosition = (Vector2){ 0.0f, 0.0f };
|
||||
GESTURES.Touch.pointCount = 0;
|
||||
}
|
||||
else if (event.touchAction == TOUCH_MOVE)
|
||||
else if (event.touchAction == TOUCH_ACTION_MOVE)
|
||||
{
|
||||
if (GESTURES.current == GESTURE_DRAG) GESTURES.Touch.eventTime = GetCurrentTime();
|
||||
if (GESTURES.current == GESTURE_DRAG) GESTURES.Touch.eventTime = rgGetCurrentTime();
|
||||
|
||||
if (!GESTURES.Swipe.start)
|
||||
{
|
||||
GESTURES.Swipe.timeDuration = GetCurrentTime();
|
||||
GESTURES.Swipe.timeDuration = rgGetCurrentTime();
|
||||
GESTURES.Swipe.start = true;
|
||||
}
|
||||
|
||||
|
@ -333,9 +347,9 @@ void ProcessGestureEvent(GestureEvent event)
|
|||
GESTURES.Hold.resetRequired = false;
|
||||
|
||||
// Detect GESTURE_DRAG
|
||||
if (Vector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.moveDownPositionA) >= MINIMUM_DRAG)
|
||||
if (rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.moveDownPositionA) >= MINIMUM_DRAG)
|
||||
{
|
||||
GESTURES.Touch.eventTime = GetCurrentTime();
|
||||
GESTURES.Touch.eventTime = rgGetCurrentTime();
|
||||
GESTURES.current = GESTURE_DRAG;
|
||||
}
|
||||
}
|
||||
|
@ -344,24 +358,24 @@ void ProcessGestureEvent(GestureEvent event)
|
|||
GESTURES.Drag.vector.y = GESTURES.Touch.moveDownPositionA.y - GESTURES.Touch.downDragPosition.y;
|
||||
}
|
||||
}
|
||||
else // Two touch points
|
||||
else if (GESTURES.Touch.pointCount == 2) // Two touch points
|
||||
{
|
||||
if (event.touchAction == TOUCH_DOWN)
|
||||
if (event.touchAction == TOUCH_ACTION_DOWN)
|
||||
{
|
||||
GESTURES.Touch.downPositionA = event.position[0];
|
||||
GESTURES.Touch.downPositionB = event.position[1];
|
||||
|
||||
//GESTURES.Pinch.distance = Vector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.downPositionB);
|
||||
//GESTURES.Pinch.distance = rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.downPositionB);
|
||||
|
||||
GESTURES.Pinch.vector.x = GESTURES.Touch.downPositionB.x - GESTURES.Touch.downPositionA.x;
|
||||
GESTURES.Pinch.vector.y = GESTURES.Touch.downPositionB.y - GESTURES.Touch.downPositionA.y;
|
||||
|
||||
GESTURES.current = GESTURE_HOLD;
|
||||
GESTURES.Hold.timeDuration = GetCurrentTime();
|
||||
GESTURES.Hold.timeDuration = rgGetCurrentTime();
|
||||
}
|
||||
else if (event.touchAction == TOUCH_MOVE)
|
||||
else if (event.touchAction == TOUCH_ACTION_MOVE)
|
||||
{
|
||||
GESTURES.Pinch.distance = Vector2Distance(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB);
|
||||
GESTURES.Pinch.distance = rgVector2Distance(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB);
|
||||
|
||||
GESTURES.Touch.downPositionA = GESTURES.Touch.moveDownPositionA;
|
||||
GESTURES.Touch.downPositionB = GESTURES.Touch.moveDownPositionB;
|
||||
|
@ -372,21 +386,21 @@ void ProcessGestureEvent(GestureEvent event)
|
|||
GESTURES.Pinch.vector.x = GESTURES.Touch.moveDownPositionB.x - GESTURES.Touch.moveDownPositionA.x;
|
||||
GESTURES.Pinch.vector.y = GESTURES.Touch.moveDownPositionB.y - GESTURES.Touch.moveDownPositionA.y;
|
||||
|
||||
if ((Vector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.moveDownPositionA) >= MINIMUM_PINCH) || (Vector2Distance(GESTURES.Touch.downPositionB, GESTURES.Touch.moveDownPositionB) >= MINIMUM_PINCH))
|
||||
if ((rgVector2Distance(GESTURES.Touch.downPositionA, GESTURES.Touch.moveDownPositionA) >= MINIMUM_PINCH) || (rgVector2Distance(GESTURES.Touch.downPositionB, GESTURES.Touch.moveDownPositionB) >= MINIMUM_PINCH))
|
||||
{
|
||||
if ((Vector2Distance(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB) - GESTURES.Pinch.distance) < 0) GESTURES.current = GESTURE_PINCH_IN;
|
||||
if ((rgVector2Distance(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB) - GESTURES.Pinch.distance) < 0) GESTURES.current = GESTURE_PINCH_IN;
|
||||
else GESTURES.current = GESTURE_PINCH_OUT;
|
||||
}
|
||||
else
|
||||
{
|
||||
GESTURES.current = GESTURE_HOLD;
|
||||
GESTURES.Hold.timeDuration = GetCurrentTime();
|
||||
GESTURES.Hold.timeDuration = rgGetCurrentTime();
|
||||
}
|
||||
|
||||
// NOTE: Angle should be inverted in Y
|
||||
GESTURES.Pinch.angle = 360.0f - Vector2Angle(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB);
|
||||
GESTURES.Pinch.angle = 360.0f - rgVector2Angle(GESTURES.Touch.moveDownPositionA, GESTURES.Touch.moveDownPositionB);
|
||||
}
|
||||
else if (event.touchAction == TOUCH_UP)
|
||||
else if (event.touchAction == TOUCH_ACTION_UP)
|
||||
{
|
||||
GESTURES.Pinch.distance = 0.0f;
|
||||
GESTURES.Pinch.angle = 0.0f;
|
||||
|
@ -396,6 +410,10 @@ void ProcessGestureEvent(GestureEvent event)
|
|||
GESTURES.current = GESTURE_NONE;
|
||||
}
|
||||
}
|
||||
else if (GESTURES.Touch.pointCount > 2) // More than two touch points
|
||||
{
|
||||
// TODO: Process gesture events for more than two points
|
||||
}
|
||||
}
|
||||
|
||||
// Update gestures detected (must be called every frame)
|
||||
|
@ -407,13 +425,13 @@ void UpdateGestures(void)
|
|||
if (((GESTURES.current == GESTURE_TAP) || (GESTURES.current == GESTURE_DOUBLETAP)) && (GESTURES.Touch.pointCount < 2))
|
||||
{
|
||||
GESTURES.current = GESTURE_HOLD;
|
||||
GESTURES.Hold.timeDuration = GetCurrentTime();
|
||||
GESTURES.Hold.timeDuration = rgGetCurrentTime();
|
||||
}
|
||||
|
||||
if (((GetCurrentTime() - GESTURES.Touch.eventTime) > TAP_TIMEOUT) && (GESTURES.current == GESTURE_DRAG) && (GESTURES.Touch.pointCount < 2))
|
||||
if (((rgGetCurrentTime() - GESTURES.Touch.eventTime) > TAP_TIMEOUT) && (GESTURES.current == GESTURE_DRAG) && (GESTURES.Touch.pointCount < 2))
|
||||
{
|
||||
GESTURES.current = GESTURE_HOLD;
|
||||
GESTURES.Hold.timeDuration = GetCurrentTime();
|
||||
GESTURES.Hold.timeDuration = rgGetCurrentTime();
|
||||
GESTURES.Hold.resetRequired = true;
|
||||
}
|
||||
|
||||
|
@ -424,14 +442,6 @@ void UpdateGestures(void)
|
|||
}
|
||||
}
|
||||
|
||||
// Get number of touch points
|
||||
int GetTouchPointsCount(void)
|
||||
{
|
||||
// NOTE: point count is calculated when ProcessGestureEvent(GestureEvent event) is called
|
||||
|
||||
return GESTURES.Touch.pointCount;
|
||||
}
|
||||
|
||||
// Get latest detected gesture
|
||||
int GetGestureDetected(void)
|
||||
{
|
||||
|
@ -446,7 +456,7 @@ float GetGestureHoldDuration(void)
|
|||
|
||||
double time = 0.0;
|
||||
|
||||
if (GESTURES.current == GESTURE_HOLD) time = GetCurrentTime() - GESTURES.Hold.timeDuration;
|
||||
if (GESTURES.current == GESTURE_HOLD) time = rgGetCurrentTime() - GESTURES.Hold.timeDuration;
|
||||
|
||||
return (float)time;
|
||||
}
|
||||
|
@ -454,7 +464,7 @@ float GetGestureHoldDuration(void)
|
|||
// Get drag vector (between initial touch point to current)
|
||||
Vector2 GetGestureDragVector(void)
|
||||
{
|
||||
// NOTE: drag vector is calculated on one touch points TOUCH_MOVE
|
||||
// NOTE: drag vector is calculated on one touch points TOUCH_ACTION_MOVE
|
||||
|
||||
return GESTURES.Drag.vector;
|
||||
}
|
||||
|
@ -463,7 +473,7 @@ Vector2 GetGestureDragVector(void)
|
|||
// NOTE: Angle in degrees, horizontal-right is 0, counterclock-wise
|
||||
float GetGestureDragAngle(void)
|
||||
{
|
||||
// NOTE: drag angle is calculated on one touch points TOUCH_UP
|
||||
// NOTE: drag angle is calculated on one touch points TOUCH_ACTION_UP
|
||||
|
||||
return GESTURES.Drag.angle;
|
||||
}
|
||||
|
@ -471,8 +481,7 @@ float GetGestureDragAngle(void)
|
|||
// Get distance between two pinch points
|
||||
Vector2 GetGesturePinchVector(void)
|
||||
{
|
||||
// NOTE: The position values used for GESTURES.Pinch.distance are not modified like the position values of [core.c]-->GetTouchPosition(int index)
|
||||
// NOTE: pinch distance is calculated on two touch points TOUCH_MOVE
|
||||
// NOTE: Pinch distance is calculated on two touch points TOUCH_ACTION_MOVE
|
||||
|
||||
return GESTURES.Pinch.vector;
|
||||
}
|
||||
|
@ -481,7 +490,7 @@ Vector2 GetGesturePinchVector(void)
|
|||
// NOTE: Angle in degrees, horizontal-right is 0, counterclock-wise
|
||||
float GetGesturePinchAngle(void)
|
||||
{
|
||||
// NOTE: pinch angle is calculated on two touch points TOUCH_MOVE
|
||||
// NOTE: pinch angle is calculated on two touch points TOUCH_ACTION_MOVE
|
||||
|
||||
return GESTURES.Pinch.angle;
|
||||
}
|
||||
|
@ -489,9 +498,8 @@ float GetGesturePinchAngle(void)
|
|||
//----------------------------------------------------------------------------------
|
||||
// Module specific Functions Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
#if defined(GESTURES_STANDALONE)
|
||||
// Returns angle from two-points vector with X-axis
|
||||
static float Vector2Angle(Vector2 v1, Vector2 v2)
|
||||
// Get angle from two-points vector with X-axis
|
||||
static float rgVector2Angle(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
float angle = atan2f(v2.y - v1.y, v2.x - v1.x)*(180.0f/PI);
|
||||
|
||||
|
@ -501,7 +509,7 @@ static float Vector2Angle(Vector2 v1, Vector2 v2)
|
|||
}
|
||||
|
||||
// Calculate distance between two Vector2
|
||||
static float Vector2Distance(Vector2 v1, Vector2 v2)
|
||||
static float rgVector2Distance(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
float result;
|
||||
|
||||
|
@ -512,10 +520,9 @@ static float Vector2Distance(Vector2 v1, Vector2 v2)
|
|||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Time measure returned are milliseconds
|
||||
static double GetCurrentTime(void)
|
||||
static double rgGetCurrentTime(void)
|
||||
{
|
||||
double time = 0;
|
||||
|
2422
raylib/rlgl.h
2422
raylib/rlgl.h
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,12 +1,25 @@
|
|||
/**********************************************************************************************
|
||||
*
|
||||
* raylib.shapes - Basic functions to draw 2d Shapes and check collisions
|
||||
* rshapes - Basic functions to draw 2d shapes and check collisions
|
||||
*
|
||||
* NOTES:
|
||||
* Shapes can be draw using 3 types of primitives: LINES, TRIANGLES and QUADS.
|
||||
* Some functions implement two drawing options: TRIANGLES and QUADS, by default TRIANGLES
|
||||
* are used but QUADS implementation can be selected with SUPPORT_QUADS_DRAW_MODE define
|
||||
*
|
||||
* Some functions define texture coordinates (rlTexCoord2f()) for the shapes and use a
|
||||
* user-provided texture with SetShapesTexture(), the pourpouse of this implementation
|
||||
* is allowing to reduce draw calls when combined with a texture-atlas.
|
||||
*
|
||||
* By default, raylib sets the default texture and rectangle at InitWindow()[rcore] to one
|
||||
* white character of default font [rtext], this way, raylib text and shapes can be draw with
|
||||
* a single draw call and it also allows users to configure it the same way with their own fonts.
|
||||
*
|
||||
* CONFIGURATION:
|
||||
*
|
||||
* #define SUPPORT_QUADS_DRAW_MODE
|
||||
* Use QUADS instead of TRIANGLES for drawing when possible.
|
||||
* Some lines-based shapes could still use lines
|
||||
* Use QUADS instead of TRIANGLES for drawing when possible. Lines-based shapes still use LINES
|
||||
*
|
||||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
|
@ -36,19 +49,23 @@
|
|||
#include "config.h" // Defines module configuration flags
|
||||
#endif
|
||||
|
||||
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2
|
||||
#include "rlgl.h" // OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2
|
||||
|
||||
#include <math.h> // Required for: sinf(), asinf(), cosf(), acosf(), sqrtf(), fabsf()
|
||||
#include <float.h> // Required for: FLT_EPSILON
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Error rate to calculate how many segments we need to draw a smooth circle,
|
||||
// taken from https://stackoverflow.com/a/2244088
|
||||
#ifndef SMOOTH_CIRCLE_ERROR_RATE
|
||||
#define SMOOTH_CIRCLE_ERROR_RATE 0.5f
|
||||
#define SMOOTH_CIRCLE_ERROR_RATE 0.5f // Circle error rate
|
||||
#endif
|
||||
#ifndef BEZIER_LINE_DIVISIONS
|
||||
#define BEZIER_LINE_DIVISIONS 24 // Bezier line divisions
|
||||
#endif
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
|
@ -122,15 +139,19 @@ void DrawLineV(Vector2 startPos, Vector2 endPos, Color color)
|
|||
// Draw a line defining thickness
|
||||
void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color)
|
||||
{
|
||||
Vector2 delta = {endPos.x-startPos.x, endPos.y-startPos.y};
|
||||
Vector2 delta = { endPos.x - startPos.x, endPos.y - startPos.y };
|
||||
float length = sqrtf(delta.x*delta.x + delta.y*delta.y);
|
||||
|
||||
if (length > 0 && thick > 0)
|
||||
if ((length > 0) && (thick > 0))
|
||||
{
|
||||
float scale = thick/(2*length);
|
||||
Vector2 radius = {-scale*delta.y, scale*delta.x};
|
||||
Vector2 strip[] = {{startPos.x-radius.x, startPos.y-radius.y}, {startPos.x+radius.x, startPos.y+radius.y},
|
||||
{endPos.x-radius.x, endPos.y-radius.y}, {endPos.x+radius.x, endPos.y+radius.y}};
|
||||
Vector2 radius = { -scale*delta.y, scale*delta.x };
|
||||
Vector2 strip[4] = {
|
||||
{ startPos.x - radius.x, startPos.y - radius.y },
|
||||
{ startPos.x + radius.x, startPos.y + radius.y },
|
||||
{ endPos.x - radius.x, endPos.y - radius.y },
|
||||
{ endPos.x + radius.x, endPos.y + radius.y }
|
||||
};
|
||||
|
||||
DrawTriangleStrip(strip, 4, color);
|
||||
}
|
||||
|
@ -139,10 +160,6 @@ void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color)
|
|||
// Draw line using cubic-bezier curves in-out
|
||||
void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color)
|
||||
{
|
||||
#ifndef BEZIER_LINE_DIVISIONS
|
||||
#define BEZIER_LINE_DIVISIONS 24 // Bezier line divisions
|
||||
#endif
|
||||
|
||||
Vector2 previous = startPos;
|
||||
Vector2 current = { 0 };
|
||||
|
||||
|
@ -185,17 +202,43 @@ void DrawLineBezierQuad(Vector2 startPos, Vector2 endPos, Vector2 controlPos, fl
|
|||
}
|
||||
}
|
||||
|
||||
// Draw lines sequence
|
||||
void DrawLineStrip(Vector2 *points, int pointsCount, Color color)
|
||||
// Draw line using cubic bezier curves with 2 control points
|
||||
void DrawLineBezierCubic(Vector2 startPos, Vector2 endPos, Vector2 startControlPos, Vector2 endControlPos, float thick, Color color)
|
||||
{
|
||||
if (pointsCount >= 2)
|
||||
const float step = 1.0f/BEZIER_LINE_DIVISIONS;
|
||||
|
||||
Vector2 previous = startPos;
|
||||
Vector2 current = { 0 };
|
||||
float t = 0.0f;
|
||||
|
||||
for (int i = 0; i <= BEZIER_LINE_DIVISIONS; i++)
|
||||
{
|
||||
rlCheckRenderBatchLimit(pointsCount);
|
||||
t = step*i;
|
||||
float a = powf(1 - t, 3);
|
||||
float b = 3*powf(1 - t, 2)*t;
|
||||
float c = 3*(1-t)*powf(t, 2);
|
||||
float d = powf(t, 3);
|
||||
|
||||
current.y = a*startPos.y + b*startControlPos.y + c*endControlPos.y + d*endPos.y;
|
||||
current.x = a*startPos.x + b*startControlPos.x + c*endControlPos.x + d*endPos.x;
|
||||
|
||||
DrawLineEx(previous, current, thick, color);
|
||||
|
||||
previous = current;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw lines sequence
|
||||
void DrawLineStrip(Vector2 *points, int pointCount, Color color)
|
||||
{
|
||||
if (pointCount >= 2)
|
||||
{
|
||||
rlCheckRenderBatchLimit(pointCount);
|
||||
|
||||
rlBegin(RL_LINES);
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
|
||||
for (int i = 0; i < pointsCount - 1; i++)
|
||||
for (int i = 0; i < pointCount - 1; i++)
|
||||
{
|
||||
rlVertex2f(points[i].x, points[i].y);
|
||||
rlVertex2f(points[i + 1].x, points[i + 1].y);
|
||||
|
@ -302,6 +345,7 @@ void DrawCircleSector(Vector2 center, float radius, float startAngle, float endA
|
|||
#endif
|
||||
}
|
||||
|
||||
// Draw a piece of a circle outlines
|
||||
void DrawCircleSectorLines(Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color)
|
||||
{
|
||||
if (radius <= 0.0f) radius = 0.1f; // Avoid div by zero issue
|
||||
|
@ -437,6 +481,7 @@ void DrawEllipseLines(int centerX, int centerY, float radiusH, float radiusV, Co
|
|||
rlEnd();
|
||||
}
|
||||
|
||||
// Draw ring
|
||||
void DrawRing(Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color)
|
||||
{
|
||||
if (startAngle == endAngle) return;
|
||||
|
@ -530,6 +575,7 @@ void DrawRing(Vector2 center, float innerRadius, float outerRadius, float startA
|
|||
#endif
|
||||
}
|
||||
|
||||
// Draw ring outline
|
||||
void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color)
|
||||
{
|
||||
if (startAngle == endAngle) return;
|
||||
|
@ -631,8 +677,6 @@ void DrawRectangleRec(Rectangle rec, Color color)
|
|||
// Draw a color-filled rectangle with pro parameters
|
||||
void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color)
|
||||
{
|
||||
rlCheckRenderBatchLimit(4);
|
||||
|
||||
Vector2 topLeft = { 0 };
|
||||
Vector2 topRight = { 0 };
|
||||
Vector2 bottomLeft = { 0 };
|
||||
|
@ -670,7 +714,11 @@ void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color
|
|||
bottomRight.y = y + (dx + rec.width)*sinRotation + (dy + rec.height)*cosRotation;
|
||||
}
|
||||
|
||||
#if defined(SUPPORT_QUADS_DRAW_MODE)
|
||||
rlCheckRenderBatchLimit(4);
|
||||
|
||||
rlSetTexture(texShapes.id);
|
||||
|
||||
rlBegin(RL_QUADS);
|
||||
|
||||
rlNormal3f(0.0f, 0.0f, 1.0f);
|
||||
|
@ -689,7 +737,25 @@ void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color
|
|||
rlVertex2f(topRight.x, topRight.y);
|
||||
|
||||
rlEnd();
|
||||
|
||||
rlSetTexture(0);
|
||||
#else
|
||||
rlCheckRenderBatchLimit(6);
|
||||
|
||||
rlBegin(RL_TRIANGLES);
|
||||
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
|
||||
rlVertex2f(topLeft.x, topLeft.y);
|
||||
rlVertex2f(bottomLeft.x, bottomLeft.y);
|
||||
rlVertex2f(topRight.x, topRight.y);
|
||||
|
||||
rlVertex2f(topRight.x, topRight.y);
|
||||
rlVertex2f(bottomLeft.x, bottomLeft.y);
|
||||
rlVertex2f(bottomRight.x, bottomRight.y);
|
||||
|
||||
rlEnd();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Draw a vertical-gradient-filled rectangle
|
||||
|
@ -710,6 +776,8 @@ void DrawRectangleGradientH(int posX, int posY, int width, int height, Color col
|
|||
// NOTE: Colors refer to corners, starting at top-lef corner and counter-clockwise
|
||||
void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color col3, Color col4)
|
||||
{
|
||||
rlCheckRenderBatchLimit(4);
|
||||
|
||||
rlSetTexture(texShapes.id);
|
||||
|
||||
rlPushMatrix();
|
||||
|
@ -1260,9 +1328,9 @@ void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, flo
|
|||
// NOTE: Vertex must be provided in counter-clockwise order
|
||||
void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color)
|
||||
{
|
||||
#if defined(SUPPORT_QUADS_DRAW_MODE)
|
||||
rlCheckRenderBatchLimit(4);
|
||||
|
||||
#if defined(SUPPORT_QUADS_DRAW_MODE)
|
||||
rlSetTexture(texShapes.id);
|
||||
|
||||
rlBegin(RL_QUADS);
|
||||
|
@ -1283,6 +1351,8 @@ void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color)
|
|||
|
||||
rlSetTexture(0);
|
||||
#else
|
||||
rlCheckRenderBatchLimit(3);
|
||||
|
||||
rlBegin(RL_TRIANGLES);
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
rlVertex2f(v1.x, v1.y);
|
||||
|
@ -1314,17 +1384,17 @@ void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color)
|
|||
// Draw a triangle fan defined by points
|
||||
// NOTE: First vertex provided is the center, shared by all triangles
|
||||
// By default, following vertex should be provided in counter-clockwise order
|
||||
void DrawTriangleFan(Vector2 *points, int pointsCount, Color color)
|
||||
void DrawTriangleFan(Vector2 *points, int pointCount, Color color)
|
||||
{
|
||||
if (pointsCount >= 3)
|
||||
if (pointCount >= 3)
|
||||
{
|
||||
rlCheckRenderBatchLimit((pointsCount - 2)*4);
|
||||
rlCheckRenderBatchLimit((pointCount - 2)*4);
|
||||
|
||||
rlSetTexture(texShapes.id);
|
||||
rlBegin(RL_QUADS);
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
|
||||
for (int i = 1; i < pointsCount - 1; i++)
|
||||
for (int i = 1; i < pointCount - 1; i++)
|
||||
{
|
||||
rlTexCoord2f(texShapesRec.x/texShapes.width, texShapesRec.y/texShapes.height);
|
||||
rlVertex2f(points[0].x, points[0].y);
|
||||
|
@ -1345,16 +1415,16 @@ void DrawTriangleFan(Vector2 *points, int pointsCount, Color color)
|
|||
|
||||
// Draw a triangle strip defined by points
|
||||
// NOTE: Every new vertex connects with previous two
|
||||
void DrawTriangleStrip(Vector2 *points, int pointsCount, Color color)
|
||||
void DrawTriangleStrip(Vector2 *points, int pointCount, Color color)
|
||||
{
|
||||
if (pointsCount >= 3)
|
||||
if (pointCount >= 3)
|
||||
{
|
||||
rlCheckRenderBatchLimit(3*(pointsCount - 2));
|
||||
rlCheckRenderBatchLimit(3*(pointCount - 2));
|
||||
|
||||
rlBegin(RL_TRIANGLES);
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
|
||||
for (int i = 2; i < pointsCount; i++)
|
||||
for (int i = 2; i < pointCount; i++)
|
||||
{
|
||||
if ((i%2) == 0)
|
||||
{
|
||||
|
@ -1533,7 +1603,11 @@ bool CheckCollisionPointRec(Vector2 point, Rectangle rec)
|
|||
// Check if point is inside circle
|
||||
bool CheckCollisionPointCircle(Vector2 point, Vector2 center, float radius)
|
||||
{
|
||||
return CheckCollisionCircles(point, 0, center, radius);
|
||||
bool collision = false;
|
||||
|
||||
collision = CheckCollisionCircles(point, 0, center, radius);
|
||||
|
||||
return collision;
|
||||
}
|
||||
|
||||
// Check if point is inside a triangle defined by three points (p1, p2, p3)
|
||||
|
@ -1584,6 +1658,8 @@ bool CheckCollisionCircles(Vector2 center1, float radius1, Vector2 center2, floa
|
|||
// NOTE: Reviewed version to take into account corner limit case
|
||||
bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec)
|
||||
{
|
||||
bool collision = false;
|
||||
|
||||
int recCenterX = (int)(rec.x + rec.width/2.0f);
|
||||
int recCenterY = (int)(rec.y + rec.height/2.0f);
|
||||
|
||||
|
@ -1599,37 +1675,45 @@ bool CheckCollisionCircleRec(Vector2 center, float radius, Rectangle rec)
|
|||
float cornerDistanceSq = (dx - rec.width/2.0f)*(dx - rec.width/2.0f) +
|
||||
(dy - rec.height/2.0f)*(dy - rec.height/2.0f);
|
||||
|
||||
return (cornerDistanceSq <= (radius*radius));
|
||||
collision = (cornerDistanceSq <= (radius*radius));
|
||||
|
||||
return collision;
|
||||
}
|
||||
|
||||
// Check the collision between two lines defined by two points each, returns collision point by reference
|
||||
bool CheckCollisionLines(Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, Vector2 endPos2, Vector2 *collisionPoint)
|
||||
{
|
||||
const float div = (endPos2.y - startPos2.y)*(endPos1.x - startPos1.x) - (endPos2.x - startPos2.x)*(endPos1.y - startPos1.y);
|
||||
bool collision = false;
|
||||
|
||||
if (div == 0.0f) return false; // WARNING: This check could not work due to float precision rounding issues...
|
||||
float div = (endPos2.y - startPos2.y)*(endPos1.x - startPos1.x) - (endPos2.x - startPos2.x)*(endPos1.y - startPos1.y);
|
||||
|
||||
const float xi = ((startPos2.x - endPos2.x)*(startPos1.x*endPos1.y - startPos1.y*endPos1.x) - (startPos1.x - endPos1.x)*(startPos2.x*endPos2.y - startPos2.y*endPos2.x))/div;
|
||||
const float yi = ((startPos2.y - endPos2.y)*(startPos1.x*endPos1.y - startPos1.y*endPos1.x) - (startPos1.y - endPos1.y)*(startPos2.x*endPos2.y - startPos2.y*endPos2.x))/div;
|
||||
if (fabsf(div) >= FLT_EPSILON)
|
||||
{
|
||||
collision = true;
|
||||
|
||||
if (xi < fminf(startPos1.x, endPos1.x) || xi > fmaxf(startPos1.x, endPos1.x)) return false;
|
||||
if (xi < fminf(startPos2.x, endPos2.x) || xi > fmaxf(startPos2.x, endPos2.x)) return false;
|
||||
if (yi < fminf(startPos1.y, endPos1.y) || yi > fmaxf(startPos1.y, endPos1.y)) return false;
|
||||
if (yi < fminf(startPos2.y, endPos2.y) || yi > fmaxf(startPos2.y, endPos2.y)) return false;
|
||||
float xi = ((startPos2.x - endPos2.x)*(startPos1.x*endPos1.y - startPos1.y*endPos1.x) - (startPos1.x - endPos1.x)*(startPos2.x*endPos2.y - startPos2.y*endPos2.x))/div;
|
||||
float yi = ((startPos2.y - endPos2.y)*(startPos1.x*endPos1.y - startPos1.y*endPos1.x) - (startPos1.y - endPos1.y)*(startPos2.x*endPos2.y - startPos2.y*endPos2.x))/div;
|
||||
|
||||
if (collisionPoint != 0)
|
||||
if (((fabsf(startPos1.x - endPos1.x) > FLT_EPSILON) && (xi < fminf(startPos1.x, endPos1.x) || (xi > fmaxf(startPos1.x, endPos1.x)))) ||
|
||||
((fabsf(startPos2.x - endPos2.x) > FLT_EPSILON) && (xi < fminf(startPos2.x, endPos2.x) || (xi > fmaxf(startPos2.x, endPos2.x)))) ||
|
||||
((fabsf(startPos1.y - endPos1.y) > FLT_EPSILON) && (yi < fminf(startPos1.y, endPos1.y) || (yi > fmaxf(startPos1.y, endPos1.y)))) ||
|
||||
((fabsf(startPos2.y - endPos2.y) > FLT_EPSILON) && (yi < fminf(startPos2.y, endPos2.y) || (yi > fmaxf(startPos2.y, endPos2.y))))) collision = false;
|
||||
|
||||
if (collision && (collisionPoint != 0))
|
||||
{
|
||||
collisionPoint->x = xi;
|
||||
collisionPoint->y = yi;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return collision;
|
||||
}
|
||||
|
||||
// Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels [threshold]
|
||||
bool CheckCollisionPointLine(Vector2 point, Vector2 p1, Vector2 p2, int threshold)
|
||||
{
|
||||
bool collision = false;
|
||||
|
||||
float dxc = point.x - p1.x;
|
||||
float dyc = point.y - p1.y;
|
||||
float dxl = p2.x - p1.x;
|
||||
|
@ -1717,7 +1801,7 @@ Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2)
|
|||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Cubic easing in-out
|
||||
// NOTE: Required for DrawLineBezier()
|
||||
// NOTE: Used by DrawLineBezier() only
|
||||
static float EaseCubicInOut(float t, float b, float c, float d)
|
||||
{
|
||||
if ((t /= 0.5f*d) < 1) return 0.5f*c*t*t*t + b;
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -56,9 +56,6 @@
|
|||
#ifndef MAX_TRACELOG_MSG_LENGTH
|
||||
#define MAX_TRACELOG_MSG_LENGTH 128 // Max length of one trace-log message
|
||||
#endif
|
||||
#ifndef MAX_UWP_MESSAGES
|
||||
#define MAX_UWP_MESSAGES 512 // Max UWP messages to process
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
|
@ -124,7 +121,7 @@ void TraceLog(int logType, const char *text, ...)
|
|||
}
|
||||
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
switch(logType)
|
||||
switch (logType)
|
||||
{
|
||||
case LOG_TRACE: __android_log_vprint(ANDROID_LOG_VERBOSE, "raylib", text, args); break;
|
||||
case LOG_DEBUG: __android_log_vprint(ANDROID_LOG_DEBUG, "raylib", text, args); break;
|
||||
|
@ -155,7 +152,7 @@ void TraceLog(int logType, const char *text, ...)
|
|||
|
||||
va_end(args);
|
||||
|
||||
if (logType == LOG_ERROR) exit(1); // If error, exit program
|
||||
if (logType == LOG_FATAL) exit(EXIT_FAILURE); // If fatal logging, exit program
|
||||
|
||||
#endif // SUPPORT_TRACELOG
|
||||
}
|
||||
|
@ -378,8 +375,8 @@ FILE *android_fopen(const char *fileName, const char *mode)
|
|||
{
|
||||
if (mode[0] == 'w')
|
||||
{
|
||||
// TODO: fopen() is mapped to android_fopen() that only grants read access
|
||||
// to assets directory through AAssetManager but we want to also be able to
|
||||
// fopen() is mapped to android_fopen() that only grants read access to
|
||||
// assets directory through AAssetManager but we want to also be able to
|
||||
// write data when required using the standard stdio FILE access functions
|
||||
// Ref: https://stackoverflow.com/questions/11294487/android-writing-saving-files-from-native-code-only
|
||||
#undef fopen
|
||||
|
@ -393,7 +390,7 @@ FILE *android_fopen(const char *fileName, const char *mode)
|
|||
|
||||
if (asset != NULL)
|
||||
{
|
||||
// Return pointer to file in the assets
|
||||
// Get pointer to file in the assets
|
||||
return funopen(asset, android_read, android_write, android_seek, android_close);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -55,9 +55,7 @@
|
|||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
#ifdef __cplusplus
|
||||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
//...
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
|
@ -67,6 +65,10 @@ extern "C" { // Prevents name mangling of functions
|
|||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
#ifdef __cplusplus
|
||||
extern "C" { // Prevents name mangling of functions
|
||||
#endif
|
||||
|
||||
#if defined(PLATFORM_ANDROID)
|
||||
void InitAssetManager(AAssetManager *manager, const char *dataPath); // Initialize asset manager from android app
|
||||
FILE *android_fopen(const char *fileName, const char *mode); // Replacement for fopen() -> Read-only!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue