mirror of
https://github.com/raysan5/raylib.git
synced 2025-12-25 10:22:33 -05:00
Compare commits
3 Commits
78faf6a120
...
7f82da0031
| Author | SHA1 | Date | |
|---|---|---|---|
| 7f82da0031 | |||
| fcaea5b1a1 | |||
| 4e8b087ffe |
36
src/external/rlsw.h
vendored
36
src/external/rlsw.h
vendored
@ -7,7 +7,7 @@
|
||||
* functionality available on rlgl.h library used by raylib, becoming a direct software
|
||||
* rendering replacement for OpenGL 1.1 backend and allowing to run raylib on GPU-less
|
||||
* devices when required
|
||||
*
|
||||
*
|
||||
* FEATURES:
|
||||
* - Rendering to custom internal framebuffer with multiple color modes supported:
|
||||
* - Color buffer: RGB - 8-bit (3:3:2) | RGB - 16-bit (5:6:5) | RGB - 24-bit (8:8:8)
|
||||
@ -50,7 +50,7 @@
|
||||
*
|
||||
* rlsw capabilities could be customized just defining some internal
|
||||
* values before library inclusion (default values listed):
|
||||
*
|
||||
*
|
||||
* #define SW_GL_FRAMEBUFFER_COPY_BGRA true
|
||||
* #define SW_GL_BINDING_COPY_TEXTURE true
|
||||
* #define SW_COLOR_BUFFER_BITS 24
|
||||
@ -60,7 +60,7 @@
|
||||
* #define SW_MAX_TEXTURE_STACK_SIZE 2
|
||||
* #define SW_MAX_TEXTURES 128
|
||||
*
|
||||
*
|
||||
*
|
||||
* LICENSE: MIT
|
||||
*
|
||||
* Copyright (c) 2025-2026 Le Juez Victor (@Bigfoot71), reviewed by Ramon Santamaria (@raysan5)
|
||||
@ -71,10 +71,10 @@
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
@ -648,7 +648,7 @@ SWAPI void swBindTexture(uint32_t id);
|
||||
// Check for SIMD vector instructions
|
||||
// NOTE: Compiler is responsible to enable required flags for host device,
|
||||
// supported features are detected at compiler init but varies depending on compiler
|
||||
// TODO: This logic must be reviewed to avoid the inclusion of multiple headers
|
||||
// TODO: This logic must be reviewed to avoid the inclusion of multiple headers
|
||||
// and enable the higher level of SIMD available
|
||||
#if defined(__FMA__) && defined(__AVX2__)
|
||||
#define SW_HAS_FMA_AVX2
|
||||
@ -896,7 +896,7 @@ typedef struct {
|
||||
int vertexCounter; // Number of vertices in 'ctx.vertexBuffer'
|
||||
|
||||
SWdraw drawMode; // Current primitive mode (e.g., lines, triangles)
|
||||
SWpoly polyMode; // Current polygon filling mode (e.g., lines, triangles)
|
||||
SWpoly polyMode; // Current polygon filling mode (e.g., lines, triangles)
|
||||
int reqVertices; // Number of vertices required for the primitive being drawn
|
||||
float pointRadius; // Rasterized point radius
|
||||
float lineWidth; // Rasterized line width
|
||||
@ -1123,9 +1123,9 @@ static inline void sw_float_to_unorm8_simd(uint8_t dst[4], const float src[4])
|
||||
float32x4_t values = vld1q_f32(src);
|
||||
float32x4_t scaled = vmulq_n_f32(values, 255.0f);
|
||||
int32x4_t clamped_s32 = vcvtq_s32_f32(scaled); // f32 -> s32 (truncated)
|
||||
int16x4_t narrow16_s = vqmovn_s32(clamped_s32);
|
||||
int16x4_t narrow16_s = vqmovn_s32(clamped_s32);
|
||||
int16x8_t combined16_s = vcombine_s16(narrow16_s, narrow16_s);
|
||||
uint8x8_t narrow8_u = vqmovun_s16(combined16_s);
|
||||
uint8x8_t narrow8_u = vqmovun_s16(combined16_s);
|
||||
vst1_lane_u32((uint32_t*)dst, vreinterpret_u32_u8(narrow8_u), 0);
|
||||
#elif defined(SW_HAS_SSE41)
|
||||
__m128 values = _mm_loadu_ps(src);
|
||||
@ -2690,9 +2690,9 @@ static inline void sw_quad_sort_cw(const sw_vertex_t* *output)
|
||||
const sw_vertex_t *input = RLSW.vertexBuffer;
|
||||
|
||||
// Calculate the centroid of the quad
|
||||
float cx = (input[0].screen[0] + input[1].screen[0] +
|
||||
float cx = (input[0].screen[0] + input[1].screen[0] +
|
||||
input[2].screen[0] + input[3].screen[0])*0.25f;
|
||||
float cy = (input[0].screen[1] + input[1].screen[1] +
|
||||
float cy = (input[0].screen[1] + input[1].screen[1] +
|
||||
input[2].screen[1] + input[3].screen[1])*0.25f;
|
||||
|
||||
// Calculate the angle of each vertex relative to the center
|
||||
@ -3615,7 +3615,7 @@ bool swInit(int w, int h)
|
||||
RLSW.loadedTextures[0].ty = 0.5f;
|
||||
|
||||
RLSW.loadedTextureCount = 1;
|
||||
|
||||
|
||||
SW_LOG("INFO: RLSW: Software renderer initialized successfully\n");
|
||||
#if defined(SW_HAS_FMA_AVX) && defined(SW_HAS_FMA_AVX2)
|
||||
SW_LOG("INFO: RLSW: Using SIMD instructions: FMA AVX\n");
|
||||
@ -4494,13 +4494,13 @@ void swDrawArrays(SWdraw mode, int offset, int count)
|
||||
const float *texMatrix = RLSW.stackTexture[RLSW.stackTextureCounter - 1];
|
||||
const float *defaultTexcoord = RLSW.current.texcoord;
|
||||
const float *defaultColor = RLSW.current.color;
|
||||
|
||||
|
||||
const float *positions = RLSW.array.positions;
|
||||
const float *texcoords = RLSW.array.texcoords;
|
||||
const uint8_t *colors = RLSW.array.colors;
|
||||
|
||||
int end = offset + count;
|
||||
|
||||
|
||||
for (int i = offset; i < end; i++)
|
||||
{
|
||||
float u, v;
|
||||
@ -4589,16 +4589,16 @@ void swDrawElements(SWdraw mode, int count, int type, const void *indices)
|
||||
const float *texMatrix = RLSW.stackTexture[RLSW.stackTextureCounter - 1];
|
||||
const float *defaultTexcoord = RLSW.current.texcoord;
|
||||
const float *defaultColor = RLSW.current.color;
|
||||
|
||||
|
||||
const float *positions = RLSW.array.positions;
|
||||
const float *texcoords = RLSW.array.texcoords;
|
||||
const uint8_t *colors = RLSW.array.colors;
|
||||
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
int index = indicesUb ? indicesUb[i] :
|
||||
int index = indicesUb ? indicesUb[i] :
|
||||
(indicesUs ? indicesUs[i] : indicesUi[i]);
|
||||
|
||||
|
||||
float u, v;
|
||||
if (texcoords)
|
||||
{
|
||||
|
||||
@ -1343,7 +1343,7 @@ int InitPlatform(void)
|
||||
// TODO: Is this needed by raylib now?
|
||||
// If so, rcore_desktop_sdl should be updated too
|
||||
//SetupFramebuffer(CORE.Window.display.width, CORE.Window.display.height);
|
||||
|
||||
|
||||
if (FLAG_IS_SET(CORE.Window.flags, FLAG_VSYNC_HINT)) RGFW_window_swapInterval(platform.window, 1);
|
||||
RGFW_window_makeCurrent(platform.window);
|
||||
|
||||
|
||||
37
src/rcore.c
37
src/rcore.c
@ -2894,7 +2894,7 @@ unsigned int *ComputeMD5(unsigned char *data, int dataSize)
|
||||
// NOTE: Returns a static int[5] array (20 bytes)
|
||||
unsigned int *ComputeSHA1(unsigned char *data, int dataSize)
|
||||
{
|
||||
#define ROTATE_LEFT(x, c) (((x) << (c)) | ((x) >> (32 - (c))))
|
||||
#define SHA1_ROTATE_LEFT(x, c) (((x) << (c)) | ((x) >> (32 - (c))))
|
||||
|
||||
static unsigned int hash[5] = { 0 }; // Hash to be returned
|
||||
|
||||
@ -2937,7 +2937,7 @@ unsigned int *ComputeSHA1(unsigned char *data, int dataSize)
|
||||
}
|
||||
|
||||
// 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] = SHA1_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];
|
||||
@ -2972,10 +2972,10 @@ unsigned int *ComputeSHA1(unsigned char *data, int dataSize)
|
||||
k = 0xCA62C1D6;
|
||||
}
|
||||
|
||||
unsigned int temp = ROTATE_LEFT(a, 5) + f + e + k + w[i];
|
||||
unsigned int temp = SHA1_ROTATE_LEFT(a, 5) + f + e + k + w[i];
|
||||
e = d;
|
||||
d = c;
|
||||
c = ROTATE_LEFT(b, 30);
|
||||
c = SHA1_ROTATE_LEFT(b, 30);
|
||||
b = a;
|
||||
a = temp;
|
||||
}
|
||||
@ -2997,9 +2997,9 @@ unsigned int *ComputeSHA1(unsigned char *data, int dataSize)
|
||||
// NOTE: Returns a static int[8] array (32 bytes)
|
||||
unsigned int *ComputeSHA256(unsigned char *data, int dataSize)
|
||||
{
|
||||
#define ROTATE_RIGHT(x, c) ((x >> c) | (x << ((sizeof(unsigned int) * 8) - c)))
|
||||
#define SHA256_A0(x) (ROTATE_RIGHT(x, 7) ^ ROTATE_RIGHT(x, 18) ^ (x >> 3))
|
||||
#define SHA256_A1(x) (ROTATE_RIGHT(x, 17) ^ ROTATE_RIGHT(x, 19) ^ (x >> 10))
|
||||
#define SHA256_ROTATE_RIGHT(x, c) ((x >> c) | (x << ((sizeof(unsigned int)*8) - c)))
|
||||
#define SHA256_A0(x) (SHA256_ROTATE_RIGHT(x, 7) ^ SHA256_ROTATE_RIGHT(x, 18) ^ (x >> 3))
|
||||
#define SHA256_A1(x) (SHA256_ROTATE_RIGHT(x, 17) ^ SHA256_ROTATE_RIGHT(x, 19) ^ (x >> 10))
|
||||
|
||||
static const unsigned int k[64] = {
|
||||
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
|
||||
@ -3020,7 +3020,7 @@ unsigned int *ComputeSHA256(unsigned char *data, int dataSize)
|
||||
0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
||||
};
|
||||
|
||||
static unsigned int hash[8];
|
||||
static unsigned int hash[8] = { 0 };
|
||||
hash[0] = 0x6A09e667;
|
||||
hash[1] = 0xbb67ae85;
|
||||
hash[2] = 0x3c6ef372;
|
||||
@ -3033,12 +3033,14 @@ unsigned int *ComputeSHA256(unsigned char *data, int dataSize)
|
||||
const unsigned long long int bitLen = ((unsigned long long int)dataSize)*8;
|
||||
unsigned long long int paddedSize = dataSize + sizeof(dataSize);
|
||||
paddedSize += (64 - (paddedSize%64));
|
||||
unsigned char *buffer = RL_CALLOC(paddedSize, sizeof(unsigned char));
|
||||
unsigned char *buffer = (unsigned char *)RL_CALLOC(paddedSize, sizeof(unsigned char));
|
||||
|
||||
memcpy(buffer, data, dataSize);
|
||||
buffer[dataSize] = 0x80;
|
||||
for (int i = 1; i <= sizeof(bitLen); i++)
|
||||
{
|
||||
buffer[(paddedSize - sizeof(bitLen)) + (i - 1)] = (bitLen >> (8*(sizeof(bitLen) - i))) & 0xFF;
|
||||
}
|
||||
|
||||
for (unsigned long long int blockN = 0; blockN < paddedSize/64; blockN++)
|
||||
{
|
||||
@ -3052,23 +3054,22 @@ unsigned int *ComputeSHA256(unsigned char *data, int dataSize)
|
||||
unsigned int h = hash[7];
|
||||
|
||||
unsigned char *block = buffer + (blockN*64);
|
||||
unsigned int w[64];
|
||||
unsigned int w[64] = { 0 };
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
w[i] =
|
||||
((unsigned int)block[i*4 + 0] << 24) |
|
||||
((unsigned int)block[i*4 + 1] << 16) |
|
||||
((unsigned int)block[i*4 + 2] << 8) |
|
||||
((unsigned int)block[i*4 + 3]);
|
||||
w[i] = ((unsigned int)block[i*4 + 0] << 24) |
|
||||
((unsigned int)block[i*4 + 1] << 16) |
|
||||
((unsigned int)block[i*4 + 2] << 8) |
|
||||
((unsigned int)block[i*4 + 3]);
|
||||
}
|
||||
for (int t = 16; t < 64; t++) w[t] = SHA256_A1(w[t - 2]) + w[t - 7] + SHA256_A0(w[t - 15]) + w[t - 16];
|
||||
|
||||
for (unsigned long long int t = 0; t < 64; t++)
|
||||
{
|
||||
unsigned int e1 = (ROTATE_RIGHT(e, 6) ^ ROTATE_RIGHT(e, 11) ^ ROTATE_RIGHT(e, 25));
|
||||
unsigned int e1 = (SHA256_ROTATE_RIGHT(e, 6) ^ SHA256_ROTATE_RIGHT(e, 11) ^ SHA256_ROTATE_RIGHT(e, 25));
|
||||
unsigned int ch = ((e & f) ^ (~e & g));
|
||||
unsigned int t1 = (h + e1 + ch + k[t] + w[t]);
|
||||
unsigned int e0 = (ROTATE_RIGHT(a, 2) ^ ROTATE_RIGHT(a, 13) ^ ROTATE_RIGHT(a, 22));
|
||||
unsigned int e0 = (SHA256_ROTATE_RIGHT(a, 2) ^ SHA256_ROTATE_RIGHT(a, 13) ^ SHA256_ROTATE_RIGHT(a, 22));
|
||||
unsigned int maj = ((a & b) ^ (a & c) ^ (b & c));
|
||||
unsigned int t2 = e0 + maj;
|
||||
|
||||
@ -3091,7 +3092,9 @@ unsigned int *ComputeSHA256(unsigned char *data, int dataSize)
|
||||
hash[6] += g;
|
||||
hash[7] += h;
|
||||
}
|
||||
|
||||
RL_FREE(buffer);
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user