Merge branch 'raysan5:master' into master
This commit is contained in:
commit
7356bb7006
|
|
@ -85,6 +85,7 @@ Some people ported raylib to other languages in the form of bindings or wrappers
|
||||||
| [raylib-cobol](https://codeberg.org/glowiak/raylib-cobol) | **auto** | [COBOL](https://gnucobol.sourceforge.io) | Public domain |
|
| [raylib-cobol](https://codeberg.org/glowiak/raylib-cobol) | **auto** | [COBOL](https://gnucobol.sourceforge.io) | Public domain |
|
||||||
| [raylib-apl](https://github.com/Brian-ED/raylib-apl) | **5.0** | [Dyalog APL](https://www.dyalog.com/) | MIT |
|
| [raylib-apl](https://github.com/Brian-ED/raylib-apl) | **5.0** | [Dyalog APL](https://www.dyalog.com/) | MIT |
|
||||||
| [raylib-jai](https://github.com/ahmedqarmout2/raylib-jai) | **5.5** | [Jai](https://github.com/BSVino/JaiPrimer/blob/master/JaiPrimer.md) | MIT |
|
| [raylib-jai](https://github.com/ahmedqarmout2/raylib-jai) | **5.5** | [Jai](https://github.com/BSVino/JaiPrimer/blob/master/JaiPrimer.md) | MIT |
|
||||||
|
| [fnl-raylib](https://github.com/0riginaln0/fnl-raylib) | **5.5** | [Fennel](https://fennel-lang.org/) | MIT |
|
||||||
|
|
||||||
### Utility Wrapers
|
### Utility Wrapers
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -54,10 +54,15 @@
|
||||||
# Define target platform: PLATFORM_DESKTOP, PLATFORM_DESKTOP_SDL, PLATFORM_DRM, PLATFORM_ANDROID, PLATFORM_WEB
|
# Define target platform: PLATFORM_DESKTOP, PLATFORM_DESKTOP_SDL, PLATFORM_DRM, PLATFORM_ANDROID, PLATFORM_WEB
|
||||||
PLATFORM ?= PLATFORM_DESKTOP
|
PLATFORM ?= PLATFORM_DESKTOP
|
||||||
|
|
||||||
ifeq ($(PLATFORM), PLATFORM_DESKTOP)
|
ifeq ($(PLATFORM),$(filter $(PLATFORM),PLATFORM_DESKTOP_GLFW PLATFORM_DESKTOP_SDL PLATFORM_DESKTOP_RGFW))
|
||||||
TARGET_PLATFORM = PLATFORM_DESKTOP_GLFW
|
TARGET_PLATFORM := $(PLATFORM)
|
||||||
|
override PLATFORM = PLATFORM_DESKTOP
|
||||||
else
|
else
|
||||||
TARGET_PLATFORM = $(PLATFORM)
|
ifeq ($(PLATFORM), PLATFORM_DESKTOP)
|
||||||
|
TARGET_PLATFORM = PLATFORM_DESKTOP_GLFW
|
||||||
|
else
|
||||||
|
TARGET_PLATFORM = $(PLATFORM)
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Define required raylib variables
|
# Define required raylib variables
|
||||||
|
|
@ -653,7 +658,7 @@ OTHERS = \
|
||||||
ifeq ($(TARGET_PLATFORM), PLATFORM_DESKTOP_GFLW)
|
ifeq ($(TARGET_PLATFORM), PLATFORM_DESKTOP_GFLW)
|
||||||
OTHERS += others/rlgl_standalone
|
OTHERS += others/rlgl_standalone
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
CURRENT_MAKEFILE = $(lastword $(MAKEFILE_LIST))
|
CURRENT_MAKEFILE = $(lastword $(MAKEFILE_LIST))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,8 @@
|
||||||
*
|
*
|
||||||
* Example create by GreenSnakeLinux (@GreenSnakeLinux),
|
* Example create by GreenSnakeLinux (@GreenSnakeLinux),
|
||||||
* lighter by oblerion (@oblerion) and
|
* lighter by oblerion (@oblerion) and
|
||||||
* reviewed by Ramon Santamaria (@raysan5)
|
* reviewed by Ramon Santamaria (@raysan5) and
|
||||||
|
* improved by danilwhale (@danilwhale)
|
||||||
*
|
*
|
||||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
||||||
* BSD-like license that allows static linking with closed source software
|
* BSD-like license that allows static linking with closed source software
|
||||||
|
|
@ -17,6 +18,16 @@
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
BUTTON_NONE = -1,
|
||||||
|
BUTTON_UP,
|
||||||
|
BUTTON_LEFT,
|
||||||
|
BUTTON_RIGHT,
|
||||||
|
BUTTON_DOWN,
|
||||||
|
BUTTON_MAX
|
||||||
|
} PadButton;
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
// Program main entry point
|
// Program main entry point
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
|
|
@ -29,24 +40,38 @@ int main(void)
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - input virtual controls");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - input virtual controls");
|
||||||
|
|
||||||
const float dpadX = 90;
|
Vector2 padPosition = { 100, 350 };
|
||||||
const float dpadY = 300;
|
float buttonRadius = 30;
|
||||||
const float dpadRad = 25.0f;//radius of each pad
|
|
||||||
Color dpadColor = BLUE;
|
|
||||||
int dpadKeydown = -1;//-1 if not down, else 0,1,2,3
|
|
||||||
|
|
||||||
|
Vector2 buttonPositions[BUTTON_MAX] =
|
||||||
const float dpadCollider[4][2]= // collider array with x,y position
|
|
||||||
{
|
{
|
||||||
{dpadX,dpadY-dpadRad*1.5f},//up
|
{ padPosition.x,padPosition.y - buttonRadius*1.5f }, // Up
|
||||||
{dpadX-dpadRad*1.5f,dpadY},//left
|
{ padPosition.x - buttonRadius*1.5f, padPosition.y }, // Left
|
||||||
{dpadX+dpadRad*1.5f,dpadY},//right
|
{ padPosition.x + buttonRadius*1.5f, padPosition.y }, // Right
|
||||||
{dpadX,dpadY+dpadRad*1.5f}//down
|
{ padPosition.x, padPosition.y + buttonRadius*1.5f } // Down
|
||||||
};
|
};
|
||||||
const char dpadLabel[4]="XYBA";//label of Dpad
|
|
||||||
|
|
||||||
float playerX=100;
|
const char *buttonLabels[BUTTON_MAX] =
|
||||||
float playerY=100;
|
{
|
||||||
|
"Y", // Up
|
||||||
|
"X", // Left
|
||||||
|
"B", // Right
|
||||||
|
"A" // Down
|
||||||
|
};
|
||||||
|
|
||||||
|
Color buttonLabelColors[BUTTON_MAX] =
|
||||||
|
{
|
||||||
|
YELLOW, // Up
|
||||||
|
BLUE, // Left
|
||||||
|
RED, // Right
|
||||||
|
GREEN // Down
|
||||||
|
};
|
||||||
|
|
||||||
|
int pressedButton = BUTTON_NONE;
|
||||||
|
Vector2 inputPosition = { 0, 0 };
|
||||||
|
|
||||||
|
Vector2 playerPosition = { (float)screenWidth/2, (float)screenHeight/2 };
|
||||||
|
float playerSpeed = 75;
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
@ -54,63 +79,89 @@ int main(void)
|
||||||
// Main game loop
|
// Main game loop
|
||||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
dpadKeydown = -1; //reset
|
if ((GetTouchPointCount() > 0))
|
||||||
int inputX = 0;
|
{
|
||||||
int inputY = 0;
|
// Use touch position
|
||||||
if(GetTouchPointCount()>0)
|
inputPosition = GetTouchPosition(0);
|
||||||
{//use touch pos
|
|
||||||
inputX = GetTouchX();
|
|
||||||
inputY = GetTouchY();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{//use mouse pos
|
|
||||||
inputX = GetMouseX();
|
|
||||||
inputY = GetMouseY();
|
|
||||||
}
|
|
||||||
for(int i=0;i<4;i++)
|
|
||||||
{
|
{
|
||||||
//test distance each collider and input < radius
|
// Use mouse position
|
||||||
if( fabsf(dpadCollider[i][1]-inputY) + fabsf(dpadCollider[i][0]-inputX) < dpadRad)
|
inputPosition = GetMousePosition();
|
||||||
{
|
|
||||||
dpadKeydown = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// move player
|
|
||||||
switch(dpadKeydown){
|
// Reset pressed button to none
|
||||||
case 0: playerY -= 50*GetFrameTime();
|
pressedButton = BUTTON_NONE;
|
||||||
break;
|
|
||||||
case 1: playerX -= 50*GetFrameTime();
|
// Make sure user is pressing left mouse button if they're from desktop
|
||||||
break;
|
if ((GetTouchPointCount() > 0) || ((GetTouchPointCount() == 0) && IsMouseButtonDown(MOUSE_BUTTON_LEFT)))
|
||||||
case 2: playerX += 50*GetFrameTime();
|
{
|
||||||
break;
|
// Find nearest D-Pad button to the input position
|
||||||
case 3: playerY += 50*GetFrameTime();
|
for (int i = 0; i < BUTTON_MAX; i++)
|
||||||
default:;
|
|
||||||
};
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
// Draw
|
|
||||||
//--------------------------------------------------------------------------
|
|
||||||
BeginDrawing();
|
|
||||||
ClearBackground(RAYWHITE);
|
|
||||||
for(int i=0;i<4;i++)
|
|
||||||
{
|
{
|
||||||
//draw all pad
|
float distX = fabsf(buttonPositions[i].x - inputPosition.x);
|
||||||
DrawCircleV((Vector2) { dpadCollider[i][0], dpadCollider[i][1] }, dpadRad, dpadColor);
|
float distY = fabsf(buttonPositions[i].y - inputPosition.y);
|
||||||
if(i!=dpadKeydown)
|
|
||||||
|
if ((distX + distY < buttonRadius))
|
||||||
{
|
{
|
||||||
//draw label
|
pressedButton = i;
|
||||||
DrawText(TextSubtext(dpadLabel,i,1),
|
break;
|
||||||
(int)dpadCollider[i][0]-7,
|
|
||||||
(int)dpadCollider[i][1]-8,20,BLACK);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move player according to pressed button
|
||||||
|
switch (pressedButton)
|
||||||
|
{
|
||||||
|
case BUTTON_UP:
|
||||||
|
{
|
||||||
|
playerPosition.y -= playerSpeed*GetFrameTime();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BUTTON_LEFT:
|
||||||
|
{
|
||||||
|
playerPosition.x -= playerSpeed*GetFrameTime();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BUTTON_RIGHT:
|
||||||
|
{
|
||||||
|
playerPosition.x += playerSpeed*GetFrameTime();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BUTTON_DOWN:
|
||||||
|
{
|
||||||
|
playerPosition.y += playerSpeed*GetFrameTime();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: break;
|
||||||
|
};
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
// Draw
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
// Draw world
|
||||||
|
DrawCircleV(playerPosition, 50, MAROON);
|
||||||
|
|
||||||
|
// Draw GUI
|
||||||
|
for (int i = 0; i < BUTTON_MAX; i++)
|
||||||
|
{
|
||||||
|
DrawCircleV(buttonPositions[i], buttonRadius, (i == pressedButton)? DARKGRAY : BLACK);
|
||||||
|
|
||||||
|
DrawText(buttonLabels[i],
|
||||||
|
(int)buttonPositions[i].x - 7, (int)buttonPositions[i].y - 8,
|
||||||
|
20, buttonLabelColors[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawText("move the player with D-Pad buttons", 10, 10, 20, DARKGRAY);
|
||||||
|
|
||||||
DrawRectangleRec((Rectangle) { playerX - 4, playerY - 4, 75, 28 }, RED);
|
|
||||||
DrawText("Player", (int)playerX, (int)playerY, 20, WHITE);
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
//--------------------------------------------------------------------------
|
//--------------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|
||||||
// De-Initialization
|
// De-Initialization
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 8.9 KiB After Width: | Height: | Size: 1.8 KiB |
|
|
@ -25,7 +25,7 @@ void main()
|
||||||
// Send vertex attributes to fragment shader
|
// Send vertex attributes to fragment shader
|
||||||
fragPosition = vec3(instanceTransform*vec4(vertexPosition, 1.0));
|
fragPosition = vec3(instanceTransform*vec4(vertexPosition, 1.0));
|
||||||
fragTexCoord = vertexTexCoord;
|
fragTexCoord = vertexTexCoord;
|
||||||
//fragColor = vertexColor;
|
fragColor = vec4(1.0);
|
||||||
fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0)));
|
fragNormal = normalize(vec3(matNormal*vec4(vertexNormal, 1.0)));
|
||||||
|
|
||||||
// Calculate final vertex position, note that we multiply mvp by instanceTransform
|
// Calculate final vertex position, note that we multiply mvp by instanceTransform
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ int main(void)
|
||||||
{
|
{
|
||||||
Matrix translation = MatrixTranslate((float)GetRandomValue(-50, 50), (float)GetRandomValue(-50, 50), (float)GetRandomValue(-50, 50));
|
Matrix translation = MatrixTranslate((float)GetRandomValue(-50, 50), (float)GetRandomValue(-50, 50), (float)GetRandomValue(-50, 50));
|
||||||
Vector3 axis = Vector3Normalize((Vector3){ (float)GetRandomValue(0, 360), (float)GetRandomValue(0, 360), (float)GetRandomValue(0, 360) });
|
Vector3 axis = Vector3Normalize((Vector3){ (float)GetRandomValue(0, 360), (float)GetRandomValue(0, 360), (float)GetRandomValue(0, 360) });
|
||||||
float angle = (float)GetRandomValue(0, 10)*DEG2RAD;
|
float angle = (float)GetRandomValue(0, 180)*DEG2RAD;
|
||||||
Matrix rotation = MatrixRotate(axis, angle);
|
Matrix rotation = MatrixRotate(axis, angle);
|
||||||
|
|
||||||
transforms[i] = MatrixMultiply(rotation, translation);
|
transforms[i] = MatrixMultiply(rotation, translation);
|
||||||
|
|
@ -73,7 +73,6 @@ int main(void)
|
||||||
// Get shader locations
|
// Get shader locations
|
||||||
shader.locs[SHADER_LOC_MATRIX_MVP] = GetShaderLocation(shader, "mvp");
|
shader.locs[SHADER_LOC_MATRIX_MVP] = GetShaderLocation(shader, "mvp");
|
||||||
shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
|
shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos");
|
||||||
shader.locs[SHADER_LOC_MATRIX_MODEL] = GetShaderLocationAttrib(shader, "instanceTransform");
|
|
||||||
|
|
||||||
// Set shader value: ambient light level
|
// Set shader value: ambient light level
|
||||||
int ambientLoc = GetShaderLocation(shader, "ambient");
|
int ambientLoc = GetShaderLocation(shader, "ambient");
|
||||||
|
|
|
||||||
|
|
@ -2543,6 +2543,11 @@
|
||||||
"name": "SHADER_LOC_BONE_MATRICES",
|
"name": "SHADER_LOC_BONE_MATRICES",
|
||||||
"value": 28,
|
"value": 28,
|
||||||
"description": "Shader location: array of matrices uniform: boneMatrices"
|
"description": "Shader location: array of matrices uniform: boneMatrices"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "SHADER_LOC_VERTEX_INSTANCE_TX",
|
||||||
|
"value": 29,
|
||||||
|
"description": "Shader location: vertex attribute: instanceTransform"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
@ -2591,8 +2596,28 @@
|
||||||
"description": "Shader uniform type: ivec4 (4 int)"
|
"description": "Shader uniform type: ivec4 (4 int)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "SHADER_UNIFORM_SAMPLER2D",
|
"name": "SHADER_UNIFORM_UINT",
|
||||||
"value": 8,
|
"value": 8,
|
||||||
|
"description": "Shader uniform type: unsigned int"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "SHADER_UNIFORM_UIVEC2",
|
||||||
|
"value": 9,
|
||||||
|
"description": "Shader uniform type: uivec2 (2 unsigned int)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "SHADER_UNIFORM_UIVEC3",
|
||||||
|
"value": 10,
|
||||||
|
"description": "Shader uniform type: uivec3 (3 unsigned int)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "SHADER_UNIFORM_UIVEC4",
|
||||||
|
"value": 11,
|
||||||
|
"description": "Shader uniform type: uivec4 (4 unsigned int)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "SHADER_UNIFORM_SAMPLER2D",
|
||||||
|
"value": 12,
|
||||||
"description": "Shader uniform type: sampler2d"
|
"description": "Shader uniform type: sampler2d"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -2543,6 +2543,11 @@ return {
|
||||||
name = "SHADER_LOC_BONE_MATRICES",
|
name = "SHADER_LOC_BONE_MATRICES",
|
||||||
value = 28,
|
value = 28,
|
||||||
description = "Shader location: array of matrices uniform: boneMatrices"
|
description = "Shader location: array of matrices uniform: boneMatrices"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = "SHADER_LOC_VERTEX_INSTANCE_TX",
|
||||||
|
value = 29,
|
||||||
|
description = "Shader location: vertex attribute: instanceTransform"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -2591,8 +2596,28 @@ return {
|
||||||
description = "Shader uniform type: ivec4 (4 int)"
|
description = "Shader uniform type: ivec4 (4 int)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name = "SHADER_UNIFORM_SAMPLER2D",
|
name = "SHADER_UNIFORM_UINT",
|
||||||
value = 8,
|
value = 8,
|
||||||
|
description = "Shader uniform type: unsigned int"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = "SHADER_UNIFORM_UIVEC2",
|
||||||
|
value = 9,
|
||||||
|
description = "Shader uniform type: uivec2 (2 unsigned int)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = "SHADER_UNIFORM_UIVEC3",
|
||||||
|
value = 10,
|
||||||
|
description = "Shader uniform type: uivec3 (3 unsigned int)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = "SHADER_UNIFORM_UIVEC4",
|
||||||
|
value = 11,
|
||||||
|
description = "Shader uniform type: uivec4 (4 unsigned int)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name = "SHADER_UNIFORM_SAMPLER2D",
|
||||||
|
value = 12,
|
||||||
description = "Shader uniform type: sampler2d"
|
description = "Shader uniform type: sampler2d"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -795,7 +795,7 @@ Enum 08: MaterialMapIndex (11 values)
|
||||||
Value[MATERIAL_MAP_IRRADIANCE]: 8
|
Value[MATERIAL_MAP_IRRADIANCE]: 8
|
||||||
Value[MATERIAL_MAP_PREFILTER]: 9
|
Value[MATERIAL_MAP_PREFILTER]: 9
|
||||||
Value[MATERIAL_MAP_BRDF]: 10
|
Value[MATERIAL_MAP_BRDF]: 10
|
||||||
Enum 09: ShaderLocationIndex (29 values)
|
Enum 09: ShaderLocationIndex (30 values)
|
||||||
Name: ShaderLocationIndex
|
Name: ShaderLocationIndex
|
||||||
Description: Shader location index
|
Description: Shader location index
|
||||||
Value[SHADER_LOC_VERTEX_POSITION]: 0
|
Value[SHADER_LOC_VERTEX_POSITION]: 0
|
||||||
|
|
@ -827,7 +827,8 @@ Enum 09: ShaderLocationIndex (29 values)
|
||||||
Value[SHADER_LOC_VERTEX_BONEIDS]: 26
|
Value[SHADER_LOC_VERTEX_BONEIDS]: 26
|
||||||
Value[SHADER_LOC_VERTEX_BONEWEIGHTS]: 27
|
Value[SHADER_LOC_VERTEX_BONEWEIGHTS]: 27
|
||||||
Value[SHADER_LOC_BONE_MATRICES]: 28
|
Value[SHADER_LOC_BONE_MATRICES]: 28
|
||||||
Enum 10: ShaderUniformDataType (9 values)
|
Value[SHADER_LOC_VERTEX_INSTANCE_TX]: 29
|
||||||
|
Enum 10: ShaderUniformDataType (13 values)
|
||||||
Name: ShaderUniformDataType
|
Name: ShaderUniformDataType
|
||||||
Description: Shader uniform data type
|
Description: Shader uniform data type
|
||||||
Value[SHADER_UNIFORM_FLOAT]: 0
|
Value[SHADER_UNIFORM_FLOAT]: 0
|
||||||
|
|
@ -838,7 +839,11 @@ Enum 10: ShaderUniformDataType (9 values)
|
||||||
Value[SHADER_UNIFORM_IVEC2]: 5
|
Value[SHADER_UNIFORM_IVEC2]: 5
|
||||||
Value[SHADER_UNIFORM_IVEC3]: 6
|
Value[SHADER_UNIFORM_IVEC3]: 6
|
||||||
Value[SHADER_UNIFORM_IVEC4]: 7
|
Value[SHADER_UNIFORM_IVEC4]: 7
|
||||||
Value[SHADER_UNIFORM_SAMPLER2D]: 8
|
Value[SHADER_UNIFORM_UINT]: 8
|
||||||
|
Value[SHADER_UNIFORM_UIVEC2]: 9
|
||||||
|
Value[SHADER_UNIFORM_UIVEC3]: 10
|
||||||
|
Value[SHADER_UNIFORM_UIVEC4]: 11
|
||||||
|
Value[SHADER_UNIFORM_SAMPLER2D]: 12
|
||||||
Enum 11: ShaderAttributeDataType (4 values)
|
Enum 11: ShaderAttributeDataType (4 values)
|
||||||
Name: ShaderAttributeDataType
|
Name: ShaderAttributeDataType
|
||||||
Description: Shader attribute data types
|
Description: Shader attribute data types
|
||||||
|
|
|
||||||
|
|
@ -507,7 +507,7 @@
|
||||||
<Value name="MATERIAL_MAP_PREFILTER" integer="9" desc="Prefilter material (NOTE: Uses GL_TEXTURE_CUBE_MAP)" />
|
<Value name="MATERIAL_MAP_PREFILTER" integer="9" desc="Prefilter material (NOTE: Uses GL_TEXTURE_CUBE_MAP)" />
|
||||||
<Value name="MATERIAL_MAP_BRDF" integer="10" desc="Brdf material" />
|
<Value name="MATERIAL_MAP_BRDF" integer="10" desc="Brdf material" />
|
||||||
</Enum>
|
</Enum>
|
||||||
<Enum name="ShaderLocationIndex" valueCount="29" desc="Shader location index">
|
<Enum name="ShaderLocationIndex" valueCount="30" desc="Shader location index">
|
||||||
<Value name="SHADER_LOC_VERTEX_POSITION" integer="0" desc="Shader location: vertex attribute: position" />
|
<Value name="SHADER_LOC_VERTEX_POSITION" integer="0" desc="Shader location: vertex attribute: position" />
|
||||||
<Value name="SHADER_LOC_VERTEX_TEXCOORD01" integer="1" desc="Shader location: vertex attribute: texcoord01" />
|
<Value name="SHADER_LOC_VERTEX_TEXCOORD01" integer="1" desc="Shader location: vertex attribute: texcoord01" />
|
||||||
<Value name="SHADER_LOC_VERTEX_TEXCOORD02" integer="2" desc="Shader location: vertex attribute: texcoord02" />
|
<Value name="SHADER_LOC_VERTEX_TEXCOORD02" integer="2" desc="Shader location: vertex attribute: texcoord02" />
|
||||||
|
|
@ -537,8 +537,9 @@
|
||||||
<Value name="SHADER_LOC_VERTEX_BONEIDS" integer="26" desc="Shader location: vertex attribute: boneIds" />
|
<Value name="SHADER_LOC_VERTEX_BONEIDS" integer="26" desc="Shader location: vertex attribute: boneIds" />
|
||||||
<Value name="SHADER_LOC_VERTEX_BONEWEIGHTS" integer="27" desc="Shader location: vertex attribute: boneWeights" />
|
<Value name="SHADER_LOC_VERTEX_BONEWEIGHTS" integer="27" desc="Shader location: vertex attribute: boneWeights" />
|
||||||
<Value name="SHADER_LOC_BONE_MATRICES" integer="28" desc="Shader location: array of matrices uniform: boneMatrices" />
|
<Value name="SHADER_LOC_BONE_MATRICES" integer="28" desc="Shader location: array of matrices uniform: boneMatrices" />
|
||||||
|
<Value name="SHADER_LOC_VERTEX_INSTANCE_TX" integer="29" desc="Shader location: vertex attribute: instanceTransform" />
|
||||||
</Enum>
|
</Enum>
|
||||||
<Enum name="ShaderUniformDataType" valueCount="9" desc="Shader uniform data type">
|
<Enum name="ShaderUniformDataType" valueCount="13" desc="Shader uniform data type">
|
||||||
<Value name="SHADER_UNIFORM_FLOAT" integer="0" desc="Shader uniform type: float" />
|
<Value name="SHADER_UNIFORM_FLOAT" integer="0" desc="Shader uniform type: float" />
|
||||||
<Value name="SHADER_UNIFORM_VEC2" integer="1" desc="Shader uniform type: vec2 (2 float)" />
|
<Value name="SHADER_UNIFORM_VEC2" integer="1" desc="Shader uniform type: vec2 (2 float)" />
|
||||||
<Value name="SHADER_UNIFORM_VEC3" integer="2" desc="Shader uniform type: vec3 (3 float)" />
|
<Value name="SHADER_UNIFORM_VEC3" integer="2" desc="Shader uniform type: vec3 (3 float)" />
|
||||||
|
|
@ -547,7 +548,11 @@
|
||||||
<Value name="SHADER_UNIFORM_IVEC2" integer="5" desc="Shader uniform type: ivec2 (2 int)" />
|
<Value name="SHADER_UNIFORM_IVEC2" integer="5" desc="Shader uniform type: ivec2 (2 int)" />
|
||||||
<Value name="SHADER_UNIFORM_IVEC3" integer="6" desc="Shader uniform type: ivec3 (3 int)" />
|
<Value name="SHADER_UNIFORM_IVEC3" integer="6" desc="Shader uniform type: ivec3 (3 int)" />
|
||||||
<Value name="SHADER_UNIFORM_IVEC4" integer="7" desc="Shader uniform type: ivec4 (4 int)" />
|
<Value name="SHADER_UNIFORM_IVEC4" integer="7" desc="Shader uniform type: ivec4 (4 int)" />
|
||||||
<Value name="SHADER_UNIFORM_SAMPLER2D" integer="8" desc="Shader uniform type: sampler2d" />
|
<Value name="SHADER_UNIFORM_UINT" integer="8" desc="Shader uniform type: unsigned int" />
|
||||||
|
<Value name="SHADER_UNIFORM_UIVEC2" integer="9" desc="Shader uniform type: uivec2 (2 unsigned int)" />
|
||||||
|
<Value name="SHADER_UNIFORM_UIVEC3" integer="10" desc="Shader uniform type: uivec3 (3 unsigned int)" />
|
||||||
|
<Value name="SHADER_UNIFORM_UIVEC4" integer="11" desc="Shader uniform type: uivec4 (4 unsigned int)" />
|
||||||
|
<Value name="SHADER_UNIFORM_SAMPLER2D" integer="12" desc="Shader uniform type: sampler2d" />
|
||||||
</Enum>
|
</Enum>
|
||||||
<Enum name="ShaderAttributeDataType" valueCount="4" desc="Shader attribute data types">
|
<Enum name="ShaderAttributeDataType" valueCount="4" desc="Shader attribute data types">
|
||||||
<Value name="SHADER_ATTRIB_FLOAT" integer="0" desc="Shader attribute type: float" />
|
<Value name="SHADER_ATTRIB_FLOAT" integer="0" desc="Shader attribute type: float" />
|
||||||
|
|
|
||||||
|
|
@ -151,6 +151,8 @@
|
||||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS 7
|
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS 7
|
||||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS 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
|
// 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
|
// NOTE: When a new shader is loaded, the following locations are tried to be set for convenience
|
||||||
|
|
|
||||||
|
|
@ -1550,7 +1550,7 @@ Music LoadMusicStreamFromMemory(const char *fileType, const unsigned char *data,
|
||||||
else if ((strcmp(fileType, ".ogg") == 0) || (strcmp(fileType, ".OGG") == 0))
|
else if ((strcmp(fileType, ".ogg") == 0) || (strcmp(fileType, ".OGG") == 0))
|
||||||
{
|
{
|
||||||
// Open ogg audio stream
|
// 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)
|
if (ctxOgg != NULL)
|
||||||
{
|
{
|
||||||
|
|
@ -2462,7 +2462,7 @@ static ma_uint32 ReadAudioBufferFramesInMixingFormat(AudioBuffer *audioBuffer, f
|
||||||
float *runningFramesOut = framesOut + (totalOutputFramesProcessed*audioBuffer->converter.channelsOut);
|
float *runningFramesOut = framesOut + (totalOutputFramesProcessed*audioBuffer->converter.channelsOut);
|
||||||
|
|
||||||
// At this point we can convert the data to our mixing format
|
// At this point we can convert the data to our mixing format
|
||||||
ma_uint64 inputFramesProcessedThisIteration = ReadAudioBufferFramesInInternalFormat(audioBuffer, inputBuffer, (ma_uint32)inputFramesToProcessThisIteration); /* Safe cast. */
|
ma_uint64 inputFramesProcessedThisIteration = ReadAudioBufferFramesInInternalFormat(audioBuffer, inputBuffer, (ma_uint32)inputFramesToProcessThisIteration);
|
||||||
ma_uint64 outputFramesProcessedThisIteration = outputFramesToProcessThisIteration;
|
ma_uint64 outputFramesProcessedThisIteration = outputFramesToProcessThisIteration;
|
||||||
ma_data_converter_process_pcm_frames(&audioBuffer->converter, inputBuffer, &inputFramesProcessedThisIteration, runningFramesOut, &outputFramesProcessedThisIteration);
|
ma_data_converter_process_pcm_frames(&audioBuffer->converter, inputBuffer, &inputFramesProcessedThisIteration, runningFramesOut, &outputFramesProcessedThisIteration);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -801,7 +801,8 @@ typedef enum {
|
||||||
SHADER_LOC_MAP_BRDF, // Shader location: sampler2d texture: brdf
|
SHADER_LOC_MAP_BRDF, // Shader location: sampler2d texture: brdf
|
||||||
SHADER_LOC_VERTEX_BONEIDS, // Shader location: vertex attribute: boneIds
|
SHADER_LOC_VERTEX_BONEIDS, // Shader location: vertex attribute: boneIds
|
||||||
SHADER_LOC_VERTEX_BONEWEIGHTS, // Shader location: vertex attribute: boneWeights
|
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;
|
} ShaderLocationIndex;
|
||||||
|
|
||||||
#define SHADER_LOC_MAP_DIFFUSE SHADER_LOC_MAP_ALBEDO
|
#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_IVEC2, // Shader uniform type: ivec2 (2 int)
|
||||||
SHADER_UNIFORM_IVEC3, // Shader uniform type: ivec3 (3 int)
|
SHADER_UNIFORM_IVEC3, // Shader uniform type: ivec3 (3 int)
|
||||||
SHADER_UNIFORM_IVEC4, // Shader uniform type: ivec4 (4 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
|
SHADER_UNIFORM_SAMPLER2D // Shader uniform type: sampler2d
|
||||||
} ShaderUniformDataType;
|
} ShaderUniformDataType;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2665,12 +2665,12 @@ inline const Vector2& operator *= (Vector2& lhs, const Matrix& rhs)
|
||||||
|
|
||||||
inline Vector2 operator / (const Vector2& lhs, const float& 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)
|
inline const Vector2& operator /= (Vector2& lhs, const float& rhs)
|
||||||
{
|
{
|
||||||
lhs = Vector2Scale(lhs, 1.0f / rhs);
|
lhs = Vector2Scale(lhs, 1.0f/rhs);
|
||||||
return lhs;
|
return lhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2759,12 +2759,12 @@ inline const Vector3& operator *= (Vector3& lhs, const Matrix& rhs)
|
||||||
|
|
||||||
inline Vector3 operator / (const Vector3& lhs, const float& 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)
|
inline const Vector3& operator /= (Vector3& lhs, const float& rhs)
|
||||||
{
|
{
|
||||||
lhs = Vector3Scale(lhs, 1.0f / rhs);
|
lhs = Vector3Scale(lhs, 1.0f/rhs);
|
||||||
return lhs;
|
return lhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2843,12 +2843,12 @@ inline const Vector4& operator *= (Vector4& lhs, const Vector4& rhs)
|
||||||
|
|
||||||
inline Vector4 operator / (const Vector4& lhs, const float& 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)
|
inline const Vector4& operator /= (Vector4& lhs, const float& rhs)
|
||||||
{
|
{
|
||||||
lhs = Vector4Scale(lhs, 1.0f / rhs);
|
lhs = Vector4Scale(lhs, 1.0f/rhs);
|
||||||
return lhs;
|
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 void CameraRoll(Camera *camera, float angle);
|
||||||
|
|
||||||
RLAPI Matrix GetCameraViewMatrix(Camera *camera);
|
RLAPI Matrix GetCameraViewMatrix(Camera *camera);
|
||||||
RLAPI Matrix GetCameraProjectionMatrix(Camera* camera, float aspect);
|
RLAPI Matrix GetCameraProjectionMatrix(Camera *camera, float aspect);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
34
src/rcore.c
34
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_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_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_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)
|
// Get handles to GLSL uniform locations (vertex shader)
|
||||||
shader.locs[SHADER_LOC_MATRIX_MVP] = rlGetLocationUniform(shader.id, RL_DEFAULT_SHADER_UNIFORM_NAME_MVP);
|
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
|
// Compute SHA-1 hash code
|
||||||
// NOTE: Returns a static int[5] array (20 bytes)
|
// 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))))
|
#define ROTATE_LEFT(x, c) (((x) << (c)) | ((x) >> (32 - (c))))
|
||||||
|
|
||||||
static unsigned int hash[5] = { 0 }; // Hash to be returned
|
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
|
// Break chunk into sixteen 32-bit words w[j], 0 <= j <= 15
|
||||||
unsigned int w[80] = {0};
|
unsigned int w[80] = {0};
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++)
|
||||||
w[i] = (msg[offset + (i * 4) + 0] << 24) |
|
{
|
||||||
(msg[offset + (i * 4) + 1] << 16) |
|
w[i] = (msg[offset + (i*4) + 0] << 24) |
|
||||||
(msg[offset + (i * 4) + 2] << 8) |
|
(msg[offset + (i*4) + 1] << 16) |
|
||||||
(msg[offset + (i * 4) + 3]);
|
(msg[offset + (i*4) + 2] << 8) |
|
||||||
|
(msg[offset + (i*4) + 3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Message schedule: extend the sixteen 32-bit words into eighty 32-bit words:
|
// Message schedule: extend the sixteen 32-bit words into eighty 32-bit words:
|
||||||
for (int i = 16; i < 80; ++i) {
|
for (int i = 16; i < 80; i++) w[i] = ROTATE_LEFT(w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16], 1);
|
||||||
w[i] = ROTATE_LEFT(w[i-3] ^ w[i-8] ^ w[i-14] ^ w[i-16], 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize hash value for this chunk
|
// Initialize hash value for this chunk
|
||||||
unsigned int a = hash[0];
|
unsigned int a = hash[0];
|
||||||
|
|
@ -2824,16 +2825,23 @@ unsigned int *ComputeSHA1(unsigned char *data, int dataSize) {
|
||||||
unsigned int f = 0;
|
unsigned int f = 0;
|
||||||
unsigned int k = 0;
|
unsigned int k = 0;
|
||||||
|
|
||||||
if (i < 20) {
|
if (i < 20)
|
||||||
|
{
|
||||||
f = (b & c) | ((~b) & d);
|
f = (b & c) | ((~b) & d);
|
||||||
k = 0x5A827999;
|
k = 0x5A827999;
|
||||||
} else if (i < 40) {
|
}
|
||||||
|
else if (i < 40)
|
||||||
|
{
|
||||||
f = b ^ c ^ d;
|
f = b ^ c ^ d;
|
||||||
k = 0x6ED9EBA1;
|
k = 0x6ED9EBA1;
|
||||||
} else if (i < 60) {
|
}
|
||||||
|
else if (i < 60)
|
||||||
|
{
|
||||||
f = (b & c) | (b & d) | (c & d);
|
f = (b & c) | (b & d) | (c & d);
|
||||||
k = 0x8F1BBCDC;
|
k = 0x8F1BBCDC;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
f = b ^ c ^ d;
|
f = b ^ c ^ d;
|
||||||
k = 0xCA62C1D6;
|
k = 0xCA62C1D6;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -355,6 +355,9 @@
|
||||||
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS 8
|
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEWEIGHTS 8
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCE_TX
|
||||||
|
#define RL_DEFAULT_SHADER_ATTRIB_LOCATION_INSTANCE_TX 9
|
||||||
|
#endif
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Types and Structures Definition
|
// Types and Structures Definition
|
||||||
|
|
@ -998,6 +1001,9 @@ RLAPI void rlLoadDrawQuad(void); // Load and draw a quad
|
||||||
#ifndef RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS
|
#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
|
#define RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS "vertexBoneWeights" // Bound by default to shader location: RL_DEFAULT_SHADER_ATTRIB_NAME_BONEWEIGHTS
|
||||||
#endif
|
#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
|
#ifndef RL_DEFAULT_SHADER_UNIFORM_NAME_MVP
|
||||||
#define RL_DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix
|
#define RL_DEFAULT_SHADER_UNIFORM_NAME_MVP "mvp" // model-view-projection matrix
|
||||||
|
|
@ -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_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_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_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
|
#ifdef RL_SUPPORT_MESH_GPU_SKINNING
|
||||||
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS, RL_DEFAULT_SHADER_ATTRIB_NAME_BONEIDS);
|
glBindAttribLocation(program, RL_DEFAULT_SHADER_ATTRIB_LOCATION_BONEIDS, RL_DEFAULT_SHADER_ATTRIB_NAME_BONEIDS);
|
||||||
|
|
|
||||||
|
|
@ -96,9 +96,9 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(SUPPORT_MESH_GENERATION)
|
#if defined(SUPPORT_MESH_GENERATION)
|
||||||
#define PAR_MALLOC(T, N) ((T*)RL_MALLOC(N*sizeof(T)))
|
#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_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_REALLOC(T, BUF, N) ((T *)RL_REALLOC(BUF, sizeof(T)*(N)))
|
||||||
#define PAR_FREE RL_FREE
|
#define PAR_FREE RL_FREE
|
||||||
|
|
||||||
#if defined(_MSC_VER) // Disable some MSVC warning
|
#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
|
// no faster, since we're transferring all the transform matrices anyway
|
||||||
instancesVboId = rlLoadVertexBuffer(instanceTransforms, instances*sizeof(float16), false);
|
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++)
|
for (unsigned int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_MATRIX_MODEL] + i);
|
rlEnableVertexAttribute(material.shader.locs[SHADER_LOC_VERTEX_INSTANCE_TX] + i);
|
||||||
rlSetVertexAttribute(material.shader.locs[SHADER_LOC_MATRIX_MODEL] + i, 4, RL_FLOAT, 0, sizeof(Matrix), i*sizeof(Vector4));
|
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_MATRIX_MODEL] + i, 1);
|
rlSetVertexAttributeDivisor(material.shader.locs[SHADER_LOC_VERTEX_INSTANCE_TX] + i, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
rlDisableVertexBuffer();
|
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
|
// Update model animated vertex data (positions and normals) for a given frame
|
||||||
// NOTE: Updated data is uploaded to GPU
|
// NOTE: Updated data is uploaded to GPU
|
||||||
void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
|
void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
|
||||||
|
|
@ -2340,14 +2340,16 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
|
||||||
{
|
{
|
||||||
boneWeight = mesh.boneWeights[boneCounter];
|
boneWeight = mesh.boneWeights[boneCounter];
|
||||||
boneId = mesh.boneIds[boneCounter];
|
boneId = mesh.boneIds[boneCounter];
|
||||||
|
|
||||||
// Early stop when no transformation will be applied
|
// Early stop when no transformation will be applied
|
||||||
if (boneWeight == 0.0f) continue;
|
if (boneWeight == 0.0f) continue;
|
||||||
animVertex = (Vector3){ mesh.vertices[vCounter], mesh.vertices[vCounter + 1], mesh.vertices[vCounter + 2] };
|
animVertex = (Vector3){ mesh.vertices[vCounter], mesh.vertices[vCounter + 1], mesh.vertices[vCounter + 2] };
|
||||||
animVertex = Vector3Transform(animVertex,model.meshes[m].boneMatrices[boneId]);
|
animVertex = Vector3Transform(animVertex,model.meshes[m].boneMatrices[boneId]);
|
||||||
mesh.animVertices[vCounter] += animVertex.x * boneWeight;
|
mesh.animVertices[vCounter] += animVertex.x*boneWeight;
|
||||||
mesh.animVertices[vCounter+1] += animVertex.y * boneWeight;
|
mesh.animVertices[vCounter+1] += animVertex.y*boneWeight;
|
||||||
mesh.animVertices[vCounter+2] += animVertex.z * boneWeight;
|
mesh.animVertices[vCounter+2] += animVertex.z*boneWeight;
|
||||||
updated = true;
|
updated = true;
|
||||||
|
|
||||||
// Normals processing
|
// Normals processing
|
||||||
// NOTE: We use meshes.baseNormals (default normal) to calculate meshes.normals (animated normals)
|
// NOTE: We use meshes.baseNormals (default normal) to calculate meshes.normals (animated normals)
|
||||||
if (mesh.normals != NULL)
|
if (mesh.normals != NULL)
|
||||||
|
|
@ -2360,6 +2362,7 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updated)
|
if (updated)
|
||||||
{
|
{
|
||||||
rlUpdateVertexBuffer(mesh.vboId[0], mesh.animVertices, mesh.vertexCount*3*sizeof(float), 0); // Update vertex position
|
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
|
#else // Use par_shapes library to generate cube mesh
|
||||||
/*
|
/*
|
||||||
// Platonic solids:
|
// Platonic solids:
|
||||||
par_shapes_mesh* par_shapes_create_tetrahedron(); // 4 sides polyhedron (pyramid)
|
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_cube(); // 6 sides polyhedron (cube)
|
||||||
par_shapes_mesh* par_shapes_create_octahedron(); // 8 sides polyhedron (diamond)
|
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_dodecahedron(); // 12 sides polyhedron
|
||||||
par_shapes_mesh* par_shapes_create_icosahedron(); // 20 sides polyhedron
|
par_shapes_mesh *par_shapes_create_icosahedron(); // 20 sides polyhedron
|
||||||
*/
|
*/
|
||||||
// Platonic solid generation: cube (6 sides)
|
// Platonic solid generation: cube (6 sides)
|
||||||
// NOTE: No normals/texcoords generated by default
|
// 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++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
points[i] = Vector3Subtract(points[i], origin3D);
|
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);
|
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++)
|
for (int i = 0; i < triangleCount; i++)
|
||||||
{
|
{
|
||||||
Vector3 a, b, c;
|
Vector3 a, b, c;
|
||||||
Vector3* vertdata = (Vector3*)mesh.vertices;
|
Vector3 *vertdata = (Vector3 *)mesh.vertices;
|
||||||
|
|
||||||
if (mesh.indices)
|
if (mesh.indices)
|
||||||
{
|
{
|
||||||
|
|
@ -4213,7 +4216,7 @@ static Model LoadOBJ(const char *fileName)
|
||||||
if (CHDIR(workingDir) != 0) TRACELOG(LOG_WARNING, "MODEL: [%s] Failed to change working directory", workingDir);
|
if (CHDIR(workingDir) != 0) TRACELOG(LOG_WARNING, "MODEL: [%s] Failed to change working directory", workingDir);
|
||||||
|
|
||||||
unsigned int dataSize = (unsigned int)strlen(fileText);
|
unsigned int dataSize = (unsigned int)strlen(fileText);
|
||||||
|
|
||||||
unsigned int flags = TINYOBJ_FLAG_TRIANGULATE;
|
unsigned int flags = TINYOBJ_FLAG_TRIANGULATE;
|
||||||
int ret = tinyobj_parse_obj(&objAttributes, &objShapes, &objShapeCount, &objMaterials, &objMaterialCount, fileText, dataSize, flags);
|
int ret = tinyobj_parse_obj(&objAttributes, &objShapes, &objShapeCount, &objMaterials, &objMaterialCount, fileText, dataSize, flags);
|
||||||
|
|
||||||
|
|
@ -4316,7 +4319,7 @@ static Model LoadOBJ(const char *fileName)
|
||||||
faceVertIndex += objAttributes.face_num_verts[faceId];
|
faceVertIndex += objAttributes.face_num_verts[faceId];
|
||||||
localMeshVertexCount += objAttributes.face_num_verts[faceId];
|
localMeshVertexCount += objAttributes.face_num_verts[faceId];
|
||||||
}
|
}
|
||||||
|
|
||||||
localMeshVertexCounts[meshIndex] = localMeshVertexCount;
|
localMeshVertexCounts[meshIndex] = localMeshVertexCount;
|
||||||
|
|
||||||
for (int i = 0; i < model.meshCount; i++)
|
for (int i = 0; i < model.meshCount; i++)
|
||||||
|
|
@ -4325,7 +4328,7 @@ static Model LoadOBJ(const char *fileName)
|
||||||
unsigned int vertexCount = localMeshVertexCounts[i];
|
unsigned int vertexCount = localMeshVertexCounts[i];
|
||||||
|
|
||||||
model.meshes[i].vertexCount = vertexCount;
|
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].vertices = (float *)MemAlloc(sizeof(float)*vertexCount*3);
|
||||||
model.meshes[i].normals = (float *)MemAlloc(sizeof(float)*vertexCount*3);
|
model.meshes[i].normals = (float *)MemAlloc(sizeof(float)*vertexCount*3);
|
||||||
|
|
@ -4360,7 +4363,7 @@ static Model LoadOBJ(const char *fileName)
|
||||||
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;
|
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;
|
if (lastMaterial != -1 && objAttributes.material_ids[faceId] != lastMaterial) newMesh = true;
|
||||||
lastMaterial = objAttributes.material_ids[faceId];
|
lastMaterial = objAttributes.material_ids[faceId];
|
||||||
|
|
@ -5657,7 +5660,7 @@ static Model LoadGLTF(const char *fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load primitive indices data (if provided)
|
// 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;
|
cgltf_accessor *attribute = mesh->primitives[p].indices;
|
||||||
|
|
||||||
|
|
@ -5674,7 +5677,7 @@ static Model LoadGLTF(const char *fileName)
|
||||||
else if (attribute->component_type == cgltf_component_type_r_8u)
|
else if (attribute->component_type == cgltf_component_type_r_8u)
|
||||||
{
|
{
|
||||||
// Init raylib mesh indices to copy glTF attribute data
|
// 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)
|
LOAD_ATTRIBUTE_CAST(attribute, 1, unsigned char, model.meshes[meshIndex].indices, unsigned short)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -5729,7 +5732,7 @@ static Model LoadGLTF(const char *fileName)
|
||||||
|
|
||||||
for (int i = 0; i < model.boneCount; i++)
|
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_float worldTransform[16];
|
||||||
cgltf_node_transform_world(node, worldTransform);
|
cgltf_node_transform_world(node, worldTransform);
|
||||||
Matrix worldMatrix = {
|
Matrix worldMatrix = {
|
||||||
|
|
|
||||||
|
|
@ -1282,7 +1282,7 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing
|
||||||
{
|
{
|
||||||
Vector2 textSize = { 0 };
|
Vector2 textSize = { 0 };
|
||||||
|
|
||||||
if ((isGpuReady && (font.texture.id == 0)) ||
|
if ((isGpuReady && (font.texture.id == 0)) ||
|
||||||
(text == NULL) || (text[0] == '\0')) return textSize; // Security check
|
(text == NULL) || (text[0] == '\0')) return textSize; // Security check
|
||||||
|
|
||||||
int size = TextLength(text); // Get size in bytes of text
|
int size = TextLength(text); // Get size in bytes of text
|
||||||
|
|
|
||||||
|
|
@ -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
|
// 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);
|
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
|
// 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
|
// (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).
|
// 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))
|
((signbit(sinDir) != 0) == (signbit(cosDir) != 0))
|
||||||
? fabsf(startingPos)
|
? fabsf(startingPos)
|
||||||
: fabsf(startingPos+width*cosDir);
|
: 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++)
|
for (int j = 0; j < height; j++)
|
||||||
{
|
{
|
||||||
// Calculate the relative position of the pixel along the gradient direction
|
// 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;
|
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 < -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
|
// Generate the color for this pixel
|
||||||
pixels[j*width + i].r = (int)((float)end.r*factor + (float)start.r*(1.0f - factor));
|
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));
|
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 y = 0; y < height; y++)
|
||||||
{
|
{
|
||||||
for (int x = 0; x < width; x++)
|
for (int x = 0; x < width; x++)
|
||||||
|
|
@ -5387,7 +5388,7 @@ static float HalfToFloat(unsigned short x)
|
||||||
const unsigned int e = (x & 0x7C00) >> 10; // Exponent
|
const unsigned int e = (x & 0x7C00) >> 10; // Exponent
|
||||||
const unsigned int m = (x & 0x03FF) << 13; // Mantissa
|
const unsigned int m = (x & 0x03FF) << 13; // Mantissa
|
||||||
const float fm = (float)m;
|
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
|
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;
|
result = *(float *)&r;
|
||||||
|
|
@ -5400,7 +5401,7 @@ static unsigned short FloatToHalf(float x)
|
||||||
{
|
{
|
||||||
unsigned short result = 0;
|
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 e = (b & 0x7F800000) >> 23; // Exponent
|
||||||
const unsigned int m = b & 0x007FFFFF; // Mantissa; in line below: 0x007FF000 = 0x00800000-0x00001000 = decimal indicator flag - initial rounding
|
const unsigned int m = b & 0x007FFFFF; // Mantissa; in line below: 0x007FF000 = 0x00800000-0x00001000 = decimal indicator flag - initial rounding
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user