Merge branch 'master' into overridable_config
This commit is contained in:
commit
e3ac719fb1
10 changed files with 391 additions and 257 deletions
|
|
@ -284,6 +284,8 @@
|
|||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS 8
|
||||
#endif
|
||||
#endif
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCE_TX 9
|
||||
|
||||
|
||||
// Default shader vertex attribute names to set location points
|
||||
// NOTE: When a new shader is loaded, the following locations are tried to be set for convenience
|
||||
|
|
|
|||
21
src/raudio.c
21
src/raudio.c
|
|
@ -1550,7 +1550,7 @@ Music LoadMusicStreamFromMemory(const char *fileType, const unsigned char *data,
|
|||
else if ((strcmp(fileType, ".ogg") == 0) || (strcmp(fileType, ".OGG") == 0))
|
||||
{
|
||||
// Open ogg audio stream
|
||||
stb_vorbis* ctxOgg = stb_vorbis_open_memory((const unsigned char *)data, dataSize, NULL, NULL);
|
||||
stb_vorbis *ctxOgg = stb_vorbis_open_memory((const unsigned char *)data, dataSize, NULL, NULL);
|
||||
|
||||
if (ctxOgg != NULL)
|
||||
{
|
||||
|
|
@ -2461,23 +2461,18 @@ static ma_uint32 ReadAudioBufferFramesInMixingFormat(AudioBuffer *audioBuffer, f
|
|||
|
||||
float *runningFramesOut = framesOut + (totalOutputFramesProcessed*audioBuffer->converter.channelsOut);
|
||||
|
||||
/* At this point we can convert the data to our mixing format. */
|
||||
ma_uint64 inputFramesProcessedThisIteration = ReadAudioBufferFramesInInternalFormat(audioBuffer, inputBuffer, (ma_uint32)inputFramesToProcessThisIteration); /* Safe cast. */
|
||||
// At this point we can convert the data to our mixing format
|
||||
ma_uint64 inputFramesProcessedThisIteration = ReadAudioBufferFramesInInternalFormat(audioBuffer, inputBuffer, (ma_uint32)inputFramesToProcessThisIteration);
|
||||
ma_uint64 outputFramesProcessedThisIteration = outputFramesToProcessThisIteration;
|
||||
ma_data_converter_process_pcm_frames(&audioBuffer->converter, inputBuffer, &inputFramesProcessedThisIteration, runningFramesOut, &outputFramesProcessedThisIteration);
|
||||
|
||||
totalOutputFramesProcessed += (ma_uint32)outputFramesProcessedThisIteration; /* Safe cast. */
|
||||
totalOutputFramesProcessed += (ma_uint32)outputFramesProcessedThisIteration; // Safe cast
|
||||
|
||||
if (inputFramesProcessedThisIteration < inputFramesToProcessThisIteration)
|
||||
{
|
||||
break; /* Ran out of input data. */
|
||||
}
|
||||
if (inputFramesProcessedThisIteration < inputFramesToProcessThisIteration) break; // Ran out of input data
|
||||
|
||||
/* This should never be hit, but will add it here for safety. Ensures we get out of the loop when no input nor output frames are processed. */
|
||||
if (inputFramesProcessedThisIteration == 0 && outputFramesProcessedThisIteration == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
// This should never be hit, but added here for safety
|
||||
// Ensures we get out of the loop when no input nor output frames are processed
|
||||
if ((inputFramesProcessedThisIteration == 0) && (outputFramesProcessedThisIteration == 0)) break;
|
||||
}
|
||||
|
||||
return totalOutputFramesProcessed;
|
||||
|
|
|
|||
|
|
@ -801,7 +801,8 @@ typedef enum {
|
|||
SHADER_LOC_MAP_BRDF, // Shader location: sampler2d texture: brdf
|
||||
SHADER_LOC_VERTEX_BONEIDS, // Shader location: vertex attribute: boneIds
|
||||
SHADER_LOC_VERTEX_BONEWEIGHTS, // Shader location: vertex attribute: boneWeights
|
||||
SHADER_LOC_BONE_MATRICES // Shader location: array of matrices uniform: boneMatrices
|
||||
SHADER_LOC_BONE_MATRICES, // Shader location: array of matrices uniform: boneMatrices
|
||||
SHADER_LOC_VERTEX_INSTANCE_TX // Shader location: vertex attribute: instanceTransform
|
||||
} ShaderLocationIndex;
|
||||
|
||||
#define SHADER_LOC_MAP_DIFFUSE SHADER_LOC_MAP_ALBEDO
|
||||
|
|
@ -817,6 +818,10 @@ typedef enum {
|
|||
SHADER_UNIFORM_IVEC2, // Shader uniform type: ivec2 (2 int)
|
||||
SHADER_UNIFORM_IVEC3, // Shader uniform type: ivec3 (3 int)
|
||||
SHADER_UNIFORM_IVEC4, // Shader uniform type: ivec4 (4 int)
|
||||
SHADER_UNIFORM_UINT, // Shader uniform type: unsigned int
|
||||
SHADER_UNIFORM_UIVEC2, // Shader uniform type: uivec2 (2 unsigned int)
|
||||
SHADER_UNIFORM_UIVEC3, // Shader uniform type: uivec3 (3 unsigned int)
|
||||
SHADER_UNIFORM_UIVEC4, // Shader uniform type: uivec4 (4 unsigned int)
|
||||
SHADER_UNIFORM_SAMPLER2D // Shader uniform type: sampler2d
|
||||
} ShaderUniformDataType;
|
||||
|
||||
|
|
@ -1177,8 +1182,8 @@ RLAPI bool IsKeyReleased(int key); // Check if a key
|
|||
RLAPI bool IsKeyUp(int key); // Check if a key is NOT being pressed
|
||||
RLAPI int GetKeyPressed(void); // Get key pressed (keycode), call it multiple times for keys queued, returns 0 when the queue is empty
|
||||
RLAPI int GetCharPressed(void); // Get char pressed (unicode), call it multiple times for chars queued, returns 0 when the queue is empty
|
||||
RLAPI const char *GetKeyName(int key); // Get name of a QWERTY key on the current keyboard layout (eg returns string 'q' for KEY_A on an AZERTY keyboard)
|
||||
RLAPI void SetExitKey(int key); // Set a custom key to exit program (default is ESC)
|
||||
RLAPI const char *GetKeyName(int key); // Get name of a QWERTY key on the current keyboard layout (eg returns string "q" for KEY_A on an AZERTY keyboard)
|
||||
|
||||
// Input-related functions: gamepads
|
||||
RLAPI bool IsGamepadAvailable(int gamepad); // Check if a gamepad is available
|
||||
|
|
|
|||
|
|
@ -328,8 +328,9 @@ RMAPI float Vector2DistanceSqr(Vector2 v1, Vector2 v2)
|
|||
return result;
|
||||
}
|
||||
|
||||
// Calculate angle between two vectors
|
||||
// NOTE: Angle is calculated from origin point (0, 0)
|
||||
// Calculate the signed angle from v1 to v2, relative to the origin (0, 0)
|
||||
// NOTE: Coordinate system convention: positive X right, positive Y down,
|
||||
// positive angles appear clockwise, and negative angles appear counterclockwise
|
||||
RMAPI float Vector2Angle(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
float result = 0.0f;
|
||||
|
|
@ -2664,12 +2665,12 @@ inline const Vector2& operator *= (Vector2& lhs, const Matrix& rhs)
|
|||
|
||||
inline Vector2 operator / (const Vector2& lhs, const float& rhs)
|
||||
{
|
||||
return Vector2Scale(lhs, 1.0f / rhs);
|
||||
return Vector2Scale(lhs, 1.0f/rhs);
|
||||
}
|
||||
|
||||
inline const Vector2& operator /= (Vector2& lhs, const float& rhs)
|
||||
{
|
||||
lhs = Vector2Scale(lhs, 1.0f / rhs);
|
||||
lhs = Vector2Scale(lhs, 1.0f/rhs);
|
||||
return lhs;
|
||||
}
|
||||
|
||||
|
|
@ -2758,12 +2759,12 @@ inline const Vector3& operator *= (Vector3& lhs, const Matrix& rhs)
|
|||
|
||||
inline Vector3 operator / (const Vector3& lhs, const float& rhs)
|
||||
{
|
||||
return Vector3Scale(lhs, 1.0f / rhs);
|
||||
return Vector3Scale(lhs, 1.0f/rhs);
|
||||
}
|
||||
|
||||
inline const Vector3& operator /= (Vector3& lhs, const float& rhs)
|
||||
{
|
||||
lhs = Vector3Scale(lhs, 1.0f / rhs);
|
||||
lhs = Vector3Scale(lhs, 1.0f/rhs);
|
||||
return lhs;
|
||||
}
|
||||
|
||||
|
|
@ -2842,12 +2843,12 @@ inline const Vector4& operator *= (Vector4& lhs, const Vector4& rhs)
|
|||
|
||||
inline Vector4 operator / (const Vector4& lhs, const float& rhs)
|
||||
{
|
||||
return Vector4Scale(lhs, 1.0f / rhs);
|
||||
return Vector4Scale(lhs, 1.0f/rhs);
|
||||
}
|
||||
|
||||
inline const Vector4& operator /= (Vector4& lhs, const float& rhs)
|
||||
{
|
||||
lhs = Vector4Scale(lhs, 1.0f / rhs);
|
||||
lhs = Vector4Scale(lhs, 1.0f/rhs);
|
||||
return lhs;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ RLAPI void CameraPitch(Camera *camera, float angle, bool lockView, bool rotateAr
|
|||
RLAPI void CameraRoll(Camera *camera, float angle);
|
||||
|
||||
RLAPI Matrix GetCameraViewMatrix(Camera *camera);
|
||||
RLAPI Matrix GetCameraProjectionMatrix(Camera* camera, float aspect);
|
||||
RLAPI Matrix GetCameraProjectionMatrix(Camera *camera, float aspect);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
|
|
|||
37
src/rcore.c
37
src/rcore.c
|
|
@ -1346,6 +1346,7 @@ Shader LoadShaderFromMemory(const char *vsCode, const char *fsCode)
|
|||
shader.locs[SHADER_LOC_VERTEX_COLOR] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR);
|
||||
shader.locs[SHADER_LOC_VERTEX_BONEIDS] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_BONEIDS);
|
||||
shader.locs[SHADER_LOC_VERTEX_BONEWEIGHTS] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS);
|
||||
shader.locs[SHADER_LOC_VERTEX_INSTANCE_TX] = rlGetLocationAttrib(shader.id, RL_DEFAULT_SHADER_ATTRIB_NAME_INSTANCE_TX);
|
||||
|
||||
// Get handles to GLSL uniform locations (vertex shader)
|
||||
shader.locs[SHADER_LOC_MATRIX_MVP] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_MVP);
|
||||
|
|
@ -2765,7 +2766,8 @@ unsigned int *ComputeMD5(unsigned char *data, int dataSize)
|
|||
|
||||
// Compute SHA-1 hash code
|
||||
// NOTE: Returns a static int[5] array (20 bytes)
|
||||
unsigned int *ComputeSHA1(unsigned char *data, int dataSize) {
|
||||
unsigned int *ComputeSHA1(unsigned char *data, int dataSize)
|
||||
{
|
||||
#define ROTATE_LEFT(x, c) (((x) << (c)) | ((x) >> (32 - (c))))
|
||||
|
||||
static unsigned int hash[5] = { 0 }; // Hash to be returned
|
||||
|
|
@ -2800,17 +2802,16 @@ unsigned int *ComputeSHA1(unsigned char *data, int dataSize) {
|
|||
{
|
||||
// Break chunk into sixteen 32-bit words w[j], 0 <= j <= 15
|
||||
unsigned int w[80] = {0};
|
||||
for (int i = 0; i < 16; i++) {
|
||||
w[i] = (msg[offset + (i * 4) + 0] << 24) |
|
||||
(msg[offset + (i * 4) + 1] << 16) |
|
||||
(msg[offset + (i * 4) + 2] << 8) |
|
||||
(msg[offset + (i * 4) + 3]);
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
w[i] = (msg[offset + (i*4) + 0] << 24) |
|
||||
(msg[offset + (i*4) + 1] << 16) |
|
||||
(msg[offset + (i*4) + 2] << 8) |
|
||||
(msg[offset + (i*4) + 3]);
|
||||
}
|
||||
|
||||
// Message schedule: extend the sixteen 32-bit words into eighty 32-bit words:
|
||||
for (int i = 16; i < 80; ++i) {
|
||||
w[i] = ROTATE_LEFT(w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16], 1);
|
||||
}
|
||||
for (int i = 16; i < 80; i++) w[i] = ROTATE_LEFT(w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16], 1);
|
||||
|
||||
// Initialize hash value for this chunk
|
||||
unsigned int a = hash[0];
|
||||
|
|
@ -2824,16 +2825,23 @@ unsigned int *ComputeSHA1(unsigned char *data, int dataSize) {
|
|||
unsigned int f = 0;
|
||||
unsigned int k = 0;
|
||||
|
||||
if (i < 20) {
|
||||
if (i < 20)
|
||||
{
|
||||
f = (b & c) | ((~b) & d);
|
||||
k = 0x5A827999;
|
||||
} else if (i < 40) {
|
||||
}
|
||||
else if (i < 40)
|
||||
{
|
||||
f = b ^ c ^ d;
|
||||
k = 0x6ED9EBA1;
|
||||
} else if (i < 60) {
|
||||
}
|
||||
else if (i < 60)
|
||||
{
|
||||
f = (b & c) | (b & d) | (c & d);
|
||||
k = 0x8F1BBCDC;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
f = b ^ c ^ d;
|
||||
k = 0xCA62C1D6;
|
||||
}
|
||||
|
|
@ -3315,7 +3323,8 @@ float GetGamepadAxisMovement(int gamepad, int axis)
|
|||
{
|
||||
float value = (axis == GAMEPAD_AXIS_LEFT_TRIGGER || axis == GAMEPAD_AXIS_RIGHT_TRIGGER)? -1.0f : 0.0f;
|
||||
|
||||
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (axis < MAX_GAMEPAD_AXIS)) {
|
||||
if ((gamepad < MAX_GAMEPADS) && CORE.Input.Gamepad.ready[gamepad] && (axis < MAX_GAMEPAD_AXIS))
|
||||
{
|
||||
float movement = value < 0.0f ? CORE.Input.Gamepad.axisState[gamepad][axis] : fabsf(CORE.Input.Gamepad.axisState[gamepad][axis]);
|
||||
|
||||
if (movement > value) value = CORE.Input.Gamepad.axisState[gamepad][axis];
|
||||
|
|
|
|||
|
|
@ -355,6 +355,9 @@
|
|||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS 8
|
||||
#endif
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCE_TX
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCE_TX 9
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
|
|
@ -998,6 +1001,9 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
|
|||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS "vertexBoneWeights" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS
|
||||
#endif
|
||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_INSTANCE_TX
|
||||
#define RL_DEFAULT_SHADER_ATTRIB_NAME_INSTANCE_TX "instanceTransform" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_NAME_INSTANCE_TX
|
||||
#endif
|
||||
|
||||
#ifndef RL_DEFAULT_SHADER_UNIFORM_NAME_MVP
|
||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix
|
||||
|
|
@ -3959,7 +3965,7 @@ void rlDrawVertexArrayElements(int offset, int count, const void *buffer)
|
|||
void rlDrawVertexArrayInstanced(int offset, int count, int instances)
|
||||
{
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
glDrawArraysInstanced(GL_TRIANGLES, 0, count, instances);
|
||||
glDrawArraysInstanced(GL_TRIANGLES, offset, count, instances);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -4216,6 +4222,7 @@ unsigned int rlLoadShaderProgram(unsigned int vShaderId, unsigned int fShaderId)
|
|||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_COLOR, RL_DEFAULT_SHADER_ATTRIB_NAME_COLOR);
|
||||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_TANGENT, RL_DEFAULT_SHADER_ATTRIB_NAME_TANGENT);
|
||||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_TEXCOORD2, RL_DEFAULT_SHADER_ATTRIB_NAME_TEXCOORD2);
|
||||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCE_TX, RL_DEFAULT_SHADER_ATTRIB_NAME_INSTANCE_TX);
|
||||
|
||||
#ifdef RL_SUPPORT_MESH_GPU_SKINNING
|
||||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS, RL_DEFAULT_SHADER_ATTRIB_NAME_BONEIDS);
|
||||
|
|
|
|||
156
src/rmodels.c
156
src/rmodels.c
|
|
@ -96,9 +96,9 @@
|
|||
#endif
|
||||
|
||||
#if SUPPORT_MESH_GENERATION
|
||||
#define PAR_MALLOC(T, N) ((T*)RL_MALLOC(N*sizeof(T)))
|
||||
#define PAR_CALLOC(T, N) ((T*)RL_CALLOC(N*sizeof(T), 1))
|
||||
#define PAR_REALLOC(T, BUF, N) ((T*)RL_REALLOC(BUF, sizeof(T)*(N)))
|
||||
#define PAR_MALLOC(T, N) ((T *)RL_MALLOC(N*sizeof(T)))
|
||||
#define PAR_CALLOC(T, N) ((T *)RL_CALLOC(N*sizeof(T), 1))
|
||||
#define PAR_REALLOC(T, BUF, N) ((T *)RL_REALLOC(BUF, sizeof(T)*(N)))
|
||||
#define PAR_FREE RL_FREE
|
||||
|
||||
#if defined(_MSC_VER) // Disable some MSVC warning
|
||||
|
|
@ -1734,12 +1734,12 @@ void DrawMeshInstanced(Mesh mesh, Material material, const Matrix *transforms, i
|
|||
// no faster, since we're transferring all the transform matrices anyway
|
||||
instancesVboId = rlLoadVertexBuffer(instanceTransforms, instances*sizeof(float16), false);
|
||||
|
||||
// Instances transformation matrices are send to shader attribute location: SHADER_LOC_MATRIX_MODEL
|
||||
// Instances transformation matrices are sent to shader attribute location: SHADER_LOC_VERTEX_INSTANCE_TX
|
||||
for (unsigned int i = 0; i < 4; i++)
|
||||
{
|
||||
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_MATRIX_MODEL] + i);
|
||||
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_MATRIX_MODEL] + i, 4, RL_FLOAT, 0, sizeof(Matrix), i*sizeof(Vector4));
|
||||
rlSetVertexAttributeDivisor(material.shader.locs[SHADER_LOC_MATRIX_MODEL] + i, 1);
|
||||
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_INSTANCE_TX] + i);
|
||||
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_INSTANCE_TX] + i, 4, RL_FLOAT, 0, sizeof(Matrix), i*sizeof(Vector4));
|
||||
rlSetVertexAttributeDivisor(material.shader.locs[SHADER_LOC_VERTEX_INSTANCE_TX] + i, 1);
|
||||
}
|
||||
|
||||
rlDisableVertexBuffer();
|
||||
|
|
@ -2308,7 +2308,7 @@ void UpdateModelAnimationBones(Model model, ModelAnimation anim, int frame)
|
|||
}
|
||||
}
|
||||
|
||||
// at least 2x speed up vs the old method
|
||||
// at least 2x speed up vs the old method
|
||||
// Update model animated vertex data (positions and normals) for a given frame
|
||||
// NOTE: Updated data is uploaded to GPU
|
||||
void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
|
||||
|
|
@ -2340,14 +2340,16 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
|
|||
{
|
||||
boneWeight = mesh.boneWeights[boneCounter];
|
||||
boneId = mesh.boneIds[boneCounter];
|
||||
|
||||
// Early stop when no transformation will be applied
|
||||
if (boneWeight == 0.0f) continue;
|
||||
animVertex = (Vector3){ mesh.vertices[vCounter], mesh.vertices[vCounter + 1], mesh.vertices[vCounter + 2] };
|
||||
animVertex = Vector3Transform(animVertex,model.meshes[m].boneMatrices[boneId]);
|
||||
mesh.animVertices[vCounter] += animVertex.x * boneWeight;
|
||||
mesh.animVertices[vCounter+1] += animVertex.y * boneWeight;
|
||||
mesh.animVertices[vCounter+2] += animVertex.z * boneWeight;
|
||||
mesh.animVertices[vCounter] += animVertex.x*boneWeight;
|
||||
mesh.animVertices[vCounter+1] += animVertex.y*boneWeight;
|
||||
mesh.animVertices[vCounter+2] += animVertex.z*boneWeight;
|
||||
updated = true;
|
||||
|
||||
// Normals processing
|
||||
// NOTE: We use meshes.baseNormals (default normal) to calculate meshes.normals (animated normals)
|
||||
if (mesh.normals != NULL)
|
||||
|
|
@ -2360,6 +2362,7 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (updated)
|
||||
{
|
||||
rlUpdateVertexBuffer(mesh.vboId[0], mesh.animVertices, mesh.vertexCount*3*sizeof(float), 0); // Update vertex position
|
||||
|
|
@ -2725,11 +2728,11 @@ Mesh GenMeshCube(float width, float height, float length)
|
|||
#else // Use par_shapes library to generate cube mesh
|
||||
/*
|
||||
// Platonic solids:
|
||||
par_shapes_mesh* par_shapes_create_tetrahedron(); // 4 sides polyhedron (pyramid)
|
||||
par_shapes_mesh* par_shapes_create_cube(); // 6 sides polyhedron (cube)
|
||||
par_shapes_mesh* par_shapes_create_octahedron(); // 8 sides polyhedron (diamond)
|
||||
par_shapes_mesh* par_shapes_create_dodecahedron(); // 12 sides polyhedron
|
||||
par_shapes_mesh* par_shapes_create_icosahedron(); // 20 sides polyhedron
|
||||
par_shapes_mesh *par_shapes_create_tetrahedron(); // 4 sides polyhedron (pyramid)
|
||||
par_shapes_mesh *par_shapes_create_cube(); // 6 sides polyhedron (cube)
|
||||
par_shapes_mesh *par_shapes_create_octahedron(); // 8 sides polyhedron (diamond)
|
||||
par_shapes_mesh *par_shapes_create_dodecahedron(); // 12 sides polyhedron
|
||||
par_shapes_mesh *par_shapes_create_icosahedron(); // 20 sides polyhedron
|
||||
*/
|
||||
// Platonic solid generation: cube (6 sides)
|
||||
// NOTE: No normals/texcoords generated by default
|
||||
|
|
@ -3840,7 +3843,7 @@ void DrawBillboardPro(Camera camera, Texture2D texture, Rectangle source, Vector
|
|||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
points[i] = Vector3Subtract(points[i], origin3D);
|
||||
if (rotation != 0.0) points[i] = Vector3RotateByAxisAngle(points[i], forward, rotation * DEG2RAD);
|
||||
if (rotation != 0.0) points[i] = Vector3RotateByAxisAngle(points[i], forward, rotation*DEG2RAD);
|
||||
points[i] = Vector3Add(points[i], position);
|
||||
}
|
||||
|
||||
|
|
@ -4049,7 +4052,7 @@ RayCollision GetRayCollisionMesh(Ray ray, Mesh mesh, Matrix transform)
|
|||
for (int i = 0; i < triangleCount; i++)
|
||||
{
|
||||
Vector3 a, b, c;
|
||||
Vector3* vertdata = (Vector3*)mesh.vertices;
|
||||
Vector3 *vertdata = (Vector3 *)mesh.vertices;
|
||||
|
||||
if (mesh.indices)
|
||||
{
|
||||
|
|
@ -4190,30 +4193,27 @@ static void BuildPoseFromParentJoints(BoneInfo *bones, int boneCount, Transform
|
|||
static Model LoadOBJ(const char *fileName)
|
||||
{
|
||||
tinyobj_attrib_t objAttributes = { 0 };
|
||||
tinyobj_shape_t* objShapes = NULL;
|
||||
tinyobj_shape_t *objShapes = NULL;
|
||||
unsigned int objShapeCount = 0;
|
||||
|
||||
tinyobj_material_t* objMaterials = NULL;
|
||||
tinyobj_material_t *objMaterials = NULL;
|
||||
unsigned int objMaterialCount = 0;
|
||||
|
||||
Model model = { 0 };
|
||||
model.transform = MatrixIdentity();
|
||||
|
||||
char* fileText = LoadFileText(fileName);
|
||||
char *fileText = LoadFileText(fileName);
|
||||
|
||||
if (fileText == NULL)
|
||||
{
|
||||
TRACELOG(LOG_ERROR, "MODEL Unable to read obj file %s", fileName);
|
||||
TRACELOG(LOG_ERROR, "MODEL: [%s] Unable to read obj file", fileName);
|
||||
return model;
|
||||
}
|
||||
|
||||
char currentDir[1024] = { 0 };
|
||||
strcpy(currentDir, GetWorkingDirectory()); // Save current working directory
|
||||
const char* workingDir = GetDirectoryPath(fileName); // Switch to OBJ directory for material path correctness
|
||||
if (CHDIR(workingDir) != 0)
|
||||
{
|
||||
TRACELOG(LOG_WARNING, "MODEL: [%s] Failed to change working directory", workingDir);
|
||||
}
|
||||
const char *workingDir = GetDirectoryPath(fileName); // Switch to OBJ directory for material path correctness
|
||||
if (CHDIR(workingDir) != 0) TRACELOG(LOG_WARNING, "MODEL: [%s] Failed to change working directory", workingDir);
|
||||
|
||||
unsigned int dataSize = (unsigned int)strlen(fileText);
|
||||
|
||||
|
|
@ -4222,7 +4222,7 @@ static Model LoadOBJ(const char *fileName)
|
|||
|
||||
if (ret != TINYOBJ_SUCCESS)
|
||||
{
|
||||
TRACELOG(LOG_ERROR, "MODEL Unable to read obj data %s", fileName);
|
||||
TRACELOG(LOG_ERROR, "MODEL: Unable to read obj data %s", fileName);
|
||||
return model;
|
||||
}
|
||||
|
||||
|
|
@ -4233,52 +4233,51 @@ static Model LoadOBJ(const char *fileName)
|
|||
int lastMaterial = -1;
|
||||
unsigned int meshIndex = 0;
|
||||
|
||||
// count meshes
|
||||
// Count meshes
|
||||
unsigned int nextShapeEnd = objAttributes.num_face_num_verts;
|
||||
|
||||
// see how many verts till the next shape
|
||||
|
||||
// See how many verts till the next shape
|
||||
if (objShapeCount > 1) nextShapeEnd = objShapes[nextShape].face_offset;
|
||||
|
||||
// walk all the faces
|
||||
// Walk all the faces
|
||||
for (unsigned int faceId = 0; faceId < objAttributes.num_faces; faceId++)
|
||||
{
|
||||
if (faceId >= nextShapeEnd)
|
||||
{
|
||||
// try to find the last vert in the next shape
|
||||
// Try to find the last vert in the next shape
|
||||
nextShape++;
|
||||
if (nextShape < objShapeCount) nextShapeEnd = objShapes[nextShape].face_offset;
|
||||
else nextShapeEnd = objAttributes.num_face_num_verts; // this is actually the total number of face verts in the file, not faces
|
||||
else nextShapeEnd = objAttributes.num_face_num_verts; // This is actually the total number of face verts in the file, not faces
|
||||
meshIndex++;
|
||||
}
|
||||
else if (lastMaterial != -1 && objAttributes.material_ids[faceId] != lastMaterial)
|
||||
else if ((lastMaterial != -1) && (objAttributes.material_ids[faceId] != lastMaterial))
|
||||
{
|
||||
meshIndex++;// if this is a new material, we need to allocate a new mesh
|
||||
meshIndex++; // If this is a new material, we need to allocate a new mesh
|
||||
}
|
||||
|
||||
lastMaterial = objAttributes.material_ids[faceId];
|
||||
faceVertIndex += objAttributes.face_num_verts[faceId];
|
||||
}
|
||||
|
||||
// allocate the base meshes and materials
|
||||
// Allocate the base meshes and materials
|
||||
model.meshCount = meshIndex + 1;
|
||||
model.meshes = (Mesh*)MemAlloc(sizeof(Mesh) * model.meshCount);
|
||||
model.meshes = (Mesh *)MemAlloc(sizeof(Mesh)*model.meshCount);
|
||||
|
||||
if (objMaterialCount > 0)
|
||||
{
|
||||
model.materialCount = objMaterialCount;
|
||||
model.materials = (Material*)MemAlloc(sizeof(Material) * objMaterialCount);
|
||||
model.materials = (Material *)MemAlloc(sizeof(Material)*objMaterialCount);
|
||||
}
|
||||
else // we must allocate at least one material
|
||||
else // We must allocate at least one material
|
||||
{
|
||||
model.materialCount = 1;
|
||||
model.materials = (Material*)MemAlloc(sizeof(Material) * 1);
|
||||
model.materials = (Material *)MemAlloc(sizeof(Material)*1);
|
||||
}
|
||||
|
||||
model.meshMaterial = (int*)MemAlloc(sizeof(int) * model.meshCount);
|
||||
model.meshMaterial = (int *)MemAlloc(sizeof(int)*model.meshCount);
|
||||
|
||||
// see how many verts are in each mesh
|
||||
unsigned int* localMeshVertexCounts = (unsigned int*)MemAlloc(sizeof(unsigned int) * model.meshCount);
|
||||
// See how many verts are in each mesh
|
||||
unsigned int *localMeshVertexCounts = (unsigned int *)MemAlloc(sizeof(unsigned int)*model.meshCount);
|
||||
|
||||
faceVertIndex = 0;
|
||||
nextShapeEnd = objAttributes.num_face_num_verts;
|
||||
|
|
@ -4287,23 +4286,22 @@ static Model LoadOBJ(const char *fileName)
|
|||
unsigned int localMeshVertexCount = 0;
|
||||
|
||||
nextShape = 1;
|
||||
if (objShapeCount > 1)
|
||||
nextShapeEnd = objShapes[nextShape].face_offset;
|
||||
if (objShapeCount > 1) nextShapeEnd = objShapes[nextShape].face_offset;
|
||||
|
||||
// walk all the faces
|
||||
// Walk all the faces
|
||||
for (unsigned int faceId = 0; faceId < objAttributes.num_faces; faceId++)
|
||||
{
|
||||
bool newMesh = false; // do we need a new mesh?
|
||||
bool newMesh = false; // Do we need a new mesh?
|
||||
if (faceId >= nextShapeEnd)
|
||||
{
|
||||
// try to find the last vert in the next shape
|
||||
// Try to find the last vert in the next shape
|
||||
nextShape++;
|
||||
if (nextShape < objShapeCount) nextShapeEnd = objShapes[nextShape].face_offset;
|
||||
else nextShapeEnd = objAttributes.num_face_num_verts; // this is actually the total number of face verts in the file, not faces
|
||||
|
||||
newMesh = true;
|
||||
}
|
||||
else if (lastMaterial != -1 && objAttributes.material_ids[faceId] != lastMaterial)
|
||||
else if ((lastMaterial != -1) && (objAttributes.material_ids[faceId] != lastMaterial))
|
||||
{
|
||||
newMesh = true;
|
||||
}
|
||||
|
|
@ -4321,50 +4319,52 @@ static Model LoadOBJ(const char *fileName)
|
|||
faceVertIndex += objAttributes.face_num_verts[faceId];
|
||||
localMeshVertexCount += objAttributes.face_num_verts[faceId];
|
||||
}
|
||||
|
||||
localMeshVertexCounts[meshIndex] = localMeshVertexCount;
|
||||
|
||||
for (int i = 0; i < model.meshCount; i++)
|
||||
{
|
||||
// allocate the buffers for each mesh
|
||||
// Allocate the buffers for each mesh
|
||||
unsigned int vertexCount = localMeshVertexCounts[i];
|
||||
|
||||
model.meshes[i].vertexCount = vertexCount;
|
||||
model.meshes[i].triangleCount = vertexCount / 3;
|
||||
model.meshes[i].triangleCount = vertexCount/3;
|
||||
|
||||
model.meshes[i].vertices = (float*)MemAlloc(sizeof(float) * vertexCount * 3);
|
||||
model.meshes[i].normals = (float*)MemAlloc(sizeof(float) * vertexCount * 3);
|
||||
model.meshes[i].texcoords = (float*)MemAlloc(sizeof(float) * vertexCount * 2);
|
||||
model.meshes[i].colors = (unsigned char*)MemAlloc(sizeof(unsigned char) * vertexCount * 4);
|
||||
model.meshes[i].vertices = (float *)MemAlloc(sizeof(float)*vertexCount*3);
|
||||
model.meshes[i].normals = (float *)MemAlloc(sizeof(float)*vertexCount*3);
|
||||
model.meshes[i].texcoords = (float *)MemAlloc(sizeof(float)*vertexCount*2);
|
||||
model.meshes[i].colors = (unsigned char *)MemAlloc(sizeof(unsigned char)*vertexCount*4);
|
||||
}
|
||||
|
||||
MemFree(localMeshVertexCounts);
|
||||
localMeshVertexCounts = NULL;
|
||||
|
||||
// fill meshes
|
||||
// Fill meshes
|
||||
faceVertIndex = 0;
|
||||
|
||||
nextShapeEnd = objAttributes.num_face_num_verts;
|
||||
|
||||
// see how many verts till the next shape
|
||||
// See how many verts till the next shape
|
||||
nextShape = 1;
|
||||
if (objShapeCount > 1) nextShapeEnd = objShapes[nextShape].face_offset;
|
||||
lastMaterial = -1;
|
||||
meshIndex = 0;
|
||||
localMeshVertexCount = 0;
|
||||
|
||||
// walk all the faces
|
||||
// Walk all the faces
|
||||
for (unsigned int faceId = 0; faceId < objAttributes.num_faces; faceId++)
|
||||
{
|
||||
bool newMesh = false; // do we need a new mesh?
|
||||
bool newMesh = false; // Do we need a new mesh?
|
||||
if (faceId >= nextShapeEnd)
|
||||
{
|
||||
// try to find the last vert in the next shape
|
||||
// Try to find the last vert in the next shape
|
||||
nextShape++;
|
||||
if (nextShape < objShapeCount) nextShapeEnd = objShapes[nextShape].face_offset;
|
||||
else nextShapeEnd = objAttributes.num_face_num_verts; // this is actually the total number of face verts in the file, not faces
|
||||
else nextShapeEnd = objAttributes.num_face_num_verts; // This is actually the total number of face verts in the file, not faces
|
||||
newMesh = true;
|
||||
}
|
||||
// if this is a new material, we need to allocate a new mesh
|
||||
|
||||
// If this is a new material, we need to allocate a new mesh
|
||||
if (lastMaterial != -1 && objAttributes.material_ids[faceId] != lastMaterial) newMesh = true;
|
||||
lastMaterial = objAttributes.material_ids[faceId];
|
||||
|
||||
|
|
@ -4375,8 +4375,7 @@ static Model LoadOBJ(const char *fileName)
|
|||
}
|
||||
|
||||
int matId = 0;
|
||||
if (lastMaterial >= 0 && lastMaterial < (int)objMaterialCount)
|
||||
matId = lastMaterial;
|
||||
if ((lastMaterial >= 0) && (lastMaterial < (int)objMaterialCount)) matId = lastMaterial;
|
||||
|
||||
model.meshMaterial[meshIndex] = matId;
|
||||
|
||||
|
|
@ -4386,19 +4385,15 @@ static Model LoadOBJ(const char *fileName)
|
|||
int normalIndex = objAttributes.faces[faceVertIndex].vn_idx;
|
||||
int texcordIndex = objAttributes.faces[faceVertIndex].vt_idx;
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
model.meshes[meshIndex].vertices[localMeshVertexCount * 3 + i] = objAttributes.vertices[vertIndex * 3 + i];
|
||||
for (int i = 0; i < 3; i++) model.meshes[meshIndex].vertices[localMeshVertexCount*3 + i] = objAttributes.vertices[vertIndex*3 + i];
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
model.meshes[meshIndex].normals[localMeshVertexCount * 3 + i] = objAttributes.normals[normalIndex * 3 + i];
|
||||
for (int i = 0; i < 3; i++) model.meshes[meshIndex].normals[localMeshVertexCount*3 + i] = objAttributes.normals[normalIndex*3 + i];
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
model.meshes[meshIndex].texcoords[localMeshVertexCount * 2 + i] = objAttributes.texcoords[texcordIndex * 2 + i];
|
||||
for (int i = 0; i < 2; i++) model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + i] = objAttributes.texcoords[texcordIndex*2 + i];
|
||||
|
||||
model.meshes[meshIndex].texcoords[localMeshVertexCount * 2 + 1] = 1.0f - model.meshes[meshIndex].texcoords[localMeshVertexCount * 2 + 1];
|
||||
model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 1] = 1.0f - model.meshes[meshIndex].texcoords[localMeshVertexCount*2 + 1];
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
model.meshes[meshIndex].colors[localMeshVertexCount * 4 + i] = 255;
|
||||
for (int i = 0; i < 4; i++) model.meshes[meshIndex].colors[localMeshVertexCount*4 + i] = 255;
|
||||
|
||||
faceVertIndex++;
|
||||
localMeshVertexCount++;
|
||||
|
|
@ -4412,8 +4407,7 @@ static Model LoadOBJ(const char *fileName)
|
|||
tinyobj_shapes_free(objShapes, objShapeCount);
|
||||
tinyobj_materials_free(objMaterials, objMaterialCount);
|
||||
|
||||
for (int i = 0; i < model.meshCount; i++)
|
||||
UploadMesh(model.meshes + i, true);
|
||||
for (int i = 0; i < model.meshCount; i++) UploadMesh(model.meshes + i, true);
|
||||
|
||||
// Restore current working directory
|
||||
if (CHDIR(currentDir) != 0)
|
||||
|
|
@ -5069,6 +5063,8 @@ static Image LoadImageFromCgltfImage(cgltf_image *cgltfImage, const char *texPat
|
|||
{
|
||||
Image image = { 0 };
|
||||
|
||||
if (cgltfImage == NULL) return image;
|
||||
|
||||
if (cgltfImage->uri != NULL) // Check if image data is provided as an uri (base64 or path)
|
||||
{
|
||||
if ((strlen(cgltfImage->uri) > 5) &&
|
||||
|
|
@ -5110,7 +5106,7 @@ static Image LoadImageFromCgltfImage(cgltf_image *cgltfImage, const char *texPat
|
|||
image = LoadImage(TextFormat("%s/%s", texPath, cgltfImage->uri));
|
||||
}
|
||||
}
|
||||
else if (cgltfImage->buffer_view->buffer->data != NULL) // Check if image is provided as data buffer
|
||||
else if (cgltfImage->buffer_view != NULL && cgltfImage->buffer_view->buffer->data != NULL) // Check if image is provided as data buffer
|
||||
{
|
||||
unsigned char *data = RL_MALLOC(cgltfImage->buffer_view->size);
|
||||
int offset = (int)cgltfImage->buffer_view->offset;
|
||||
|
|
@ -5664,7 +5660,7 @@ static Model LoadGLTF(const char *fileName)
|
|||
}
|
||||
|
||||
// Load primitive indices data (if provided)
|
||||
if (mesh->primitives[p].indices != NULL)
|
||||
if ((mesh->primitives[p].indices != NULL) && (mesh->primitives[p].indices->buffer_view != NULL))
|
||||
{
|
||||
cgltf_accessor *attribute = mesh->primitives[p].indices;
|
||||
|
||||
|
|
@ -5681,7 +5677,7 @@ static Model LoadGLTF(const char *fileName)
|
|||
else if (attribute->component_type == cgltf_component_type_r_8u)
|
||||
{
|
||||
// Init raylib mesh indices to copy glTF attribute data
|
||||
model.meshes[meshIndex].indices = RL_MALLOC(attribute->count * sizeof(unsigned short));
|
||||
model.meshes[meshIndex].indices = RL_MALLOC(attribute->count*sizeof(unsigned short));
|
||||
LOAD_ATTRIBUTE_CAST(attribute, 1, unsigned char, model.meshes[meshIndex].indices, unsigned short)
|
||||
|
||||
}
|
||||
|
|
@ -5736,7 +5732,7 @@ static Model LoadGLTF(const char *fileName)
|
|||
|
||||
for (int i = 0; i < model.boneCount; i++)
|
||||
{
|
||||
cgltf_node* node = skin.joints[i];
|
||||
cgltf_node *node = skin.joints[i];
|
||||
cgltf_float worldTransform[16];
|
||||
cgltf_node_transform_world(node, worldTransform);
|
||||
Matrix worldMatrix = {
|
||||
|
|
|
|||
|
|
@ -1282,7 +1282,7 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing
|
|||
{
|
||||
Vector2 textSize = { 0 };
|
||||
|
||||
if ((isGpuReady && (font.texture.id == 0)) ||
|
||||
if ((isGpuReady && (font.texture.id == 0)) ||
|
||||
(text == NULL) || (text[0] == '\0')) return textSize; // Security check
|
||||
|
||||
int size = TextLength(text); // Get size in bytes of text
|
||||
|
|
@ -2325,9 +2325,9 @@ static Font LoadBMFont(const char *fileName)
|
|||
// Convert hexadecimal to decimal (single digit)
|
||||
static unsigned char HexToInt(char hex)
|
||||
{
|
||||
if (hex >= '0' && hex <= '9') return hex - '0';
|
||||
else if (hex >= 'a' && hex <= 'f') return hex - 'a' + 10;
|
||||
else if (hex >= 'A' && hex <= 'F') return hex - 'A' + 10;
|
||||
if ((hex >= '0') && (hex <= '9')) return hex - '0';
|
||||
else if ((hex >= 'a') && (hex <= 'f')) return hex - 'a' + 10;
|
||||
else if ((hex >= 'A') && (hex <= 'F')) return hex - 'A' + 10;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -829,11 +829,11 @@ Image GenImageGradientLinear(int width, int height, int direction, Color start,
|
|||
|
||||
// Calculate how far the top-left pixel is along the gradient direction from the center of said gradient
|
||||
float startingPos = 0.5f - (cosDir*width/2) - (sinDir*height/2);
|
||||
// With directions that lie in the first or third quadrant (i.e. from top-left to
|
||||
// With directions that lie in the first or third quadrant (i.e. from top-left to
|
||||
// bottom-right or vice-versa), pixel (0, 0) is the farthest point on the gradient
|
||||
// (i.e. the pixel which should become one of the gradient's ends color); while for
|
||||
// directions that lie in the second or fourth quadrant, that point is pixel (width, 0).
|
||||
float maxPosValue =
|
||||
float maxPosValue =
|
||||
((signbit(sinDir) != 0) == (signbit(cosDir) != 0))
|
||||
? fabsf(startingPos)
|
||||
: fabsf(startingPos+width*cosDir);
|
||||
|
|
@ -842,12 +842,12 @@ Image GenImageGradientLinear(int width, int height, int direction, Color start,
|
|||
for (int j = 0; j < height; j++)
|
||||
{
|
||||
// Calculate the relative position of the pixel along the gradient direction
|
||||
float pos = (startingPos + (i*cosDir + j*sinDir)) / maxPosValue;
|
||||
float pos = (startingPos + (i*cosDir + j*sinDir))/maxPosValue;
|
||||
|
||||
float factor = pos;
|
||||
factor = (factor > 1.0f)? 1.0f : factor; // Clamp to [-1,1]
|
||||
factor = (factor < -1.0f)? -1.0f : factor; // Clamp to [-1,1]
|
||||
factor = factor / 2 + 0.5f;
|
||||
factor = factor/2.0f + 0.5f;
|
||||
|
||||
// Generate the color for this pixel
|
||||
pixels[j*width + i].r = (int)((float)end.r*factor + (float)start.r*(1.0f - factor));
|
||||
|
|
@ -1007,7 +1007,8 @@ Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float
|
|||
{
|
||||
Color *pixels = (Color *)RL_MALLOC(width*height*sizeof(Color));
|
||||
|
||||
float aspectRatio = (float)width / (float)height;
|
||||
float aspectRatio = (float)width/(float)height;
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
for (int x = 0; x < width; x++)
|
||||
|
|
@ -3567,7 +3568,7 @@ void ImageDrawLineEx(Image *dst, Vector2 start, Vector2 end, int thick, Color co
|
|||
ImageDrawLine(dst, x1, y1, x2, y2, color);
|
||||
|
||||
// Determine if the line is more horizontal or vertical
|
||||
if (dx != 0 && abs(dy/dx) < 1)
|
||||
if ((dx != 0) && (abs(dy/dx) < 1))
|
||||
{
|
||||
// Line is more horizontal
|
||||
// Calculate half the width of the line
|
||||
|
|
@ -5387,7 +5388,7 @@ static float HalfToFloat(unsigned short x)
|
|||
const unsigned int e = (x & 0x7C00) >> 10; // Exponent
|
||||
const unsigned int m = (x & 0x03FF) << 13; // Mantissa
|
||||
const float fm = (float)m;
|
||||
const unsigned int v = (*(unsigned int*)&fm) >> 23; // Evil log2 bit hack to count leading zeros in denormalized format
|
||||
const unsigned int v = (*(unsigned int *)&fm) >> 23; // Evil log2 bit hack to count leading zeros in denormalized format
|
||||
const unsigned int r = (x & 0x8000) << 16 | (e != 0)*((e + 112) << 23 | m) | ((e == 0)&(m != 0))*((v - 37) << 23 | ((m << (150 - v)) & 0x007FE000)); // sign : normalized : denormalized
|
||||
|
||||
result = *(float *)&r;
|
||||
|
|
@ -5400,7 +5401,7 @@ static unsigned short FloatToHalf(float x)
|
|||
{
|
||||
unsigned short result = 0;
|
||||
|
||||
const unsigned int b = (*(unsigned int*) & x) + 0x00001000; // Round-to-nearest-even: add last bit after truncated mantissa
|
||||
const unsigned int b = (*(unsigned int *) & x) + 0x00001000; // Round-to-nearest-even: add last bit after truncated mantissa
|
||||
const unsigned int e = (b & 0x7F800000) >> 23; // Exponent
|
||||
const unsigned int m = b & 0x007FFFFF; // Mantissa; in line below: 0x007FF000 = 0x00800000-0x00001000 = decimal indicator flag - initial rounding
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue